anmolsahai commited on
Commit
1ea97da
1 Parent(s): ddbf0ba
Files changed (1) hide show
  1. langchain_pipeline.py +18 -18
langchain_pipeline.py CHANGED
@@ -2,8 +2,8 @@ import os
2
  from pdfminer import high_level
3
  from langchain_core.prompts import PromptTemplate
4
  from google.cloud import aiplatform
5
- from google.cloud.aiplatform import ModelServiceClient
6
- from google.cloud.aiplatform.gapic.schema import predict
7
  import base64
8
 
9
  # Initialize the Google AI Platform
@@ -11,15 +11,15 @@ aiplatform.init(project="akroda", location="us-central1")
11
 
12
  # Define the documents (base64-encoded PDF content)
13
  documents = [
14
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeODgxNz5dL1Jvb3QgMTU0IDAgUi9TaXplIDE2Nj4+CnN0YXJ0eHJlZgoyMTY0NjkKJSVFT0YK")),
15
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeLjz9MKNijU+PgpzdGFydHhyZWYKMTMxMDY0CiUlRU9GCg==")),
16
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeLjz9MKNiAwZDU0YTVlNzllMWRhYWY1ZDQ2YjI+XS9Sb290IDE3NyAwIFIvU2l6ZSAxODc+PgpzdGFydHhyZWYKMjA3NTk5CiUlRU9GCg==")),
17
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeLjz9ML1Jvb3QgMTg5IDAgUi9TaXplIDE5OT4+CnN0YXJ0eHJlZgoxOTgzNzMKJSVFT0YK")),
18
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xCcnCmVuZHN0cmVhbQplbmRvYmoKc3RhcnR4cmVmCjIwOTgyNQolJUVPRgo=")),
19
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLj+CnN0YXJ0eHJlZgoyMTk5MDYKJSVFT0YK")),
20
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJiUlRU9GCg==")),
21
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJe90IDMwOCAwIFIvU2l6ZSAzMTg+PgpzdGFydHhyZWYKMjcwNzU3CiUlRU9GCg==")),
22
- predict.instance.TextDocument(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjUNJeLjz9MNCjcgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgNjc1NzgvTyA5L0UgNjAyNDYvTiAxL1QgNjcyODcvSCBbIDQ4MyAxNTRdPj4NZW5kb2JxDSAgICAgICAgICAgICAgICAgICAgDQoyMiAwIG9iag08PC9EZWNvZGVQYXJtczw8L0NvbHVtbnMgNC9QcmVkaWN0b3IgMTI+Pi9GaWx0ZXIvRmxhdGVEZWNvZGUvSURbPDE3NzU4MkJFODc4MzRFQjNBOEM3RkIzQTgyRjFFMEFCPjw5MzI2Qjk4REM4NjQ2RTRCODI3MzZFQUEzOENEQjFBQj5dL0luZGV4WzcgMjhdL0luZm8gNiAwIFIvTGVuZ3RoIDgzL1ByZXYgNjcyODgvUm9vdCA4IDAgUi9TaXplIDM1L1R5cGUvWFPRg0K"))
23
  ]
24
 
25
  text1 = """
@@ -64,18 +64,18 @@ val = prompt.format(
64
  min_transaction_overdraft=min_transaction_overdraft,
65
  )
66
 
67
- generation_config = generative_model.GenerationConfig(
68
  max_output_tokens=8192,
69
  temperature=1,
70
  top_p=0.95,
71
  )
72
 
73
- safety_settings = generative_model.SafetySettings(
74
  harm_category_settings={
75
- generative_model.HarmCategory.HARM_CATEGORY_HATE_SPEECH: generative_model.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
76
- generative_model.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: generative_model.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
77
- generative_model.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: generative_model.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
78
- generative_model.HarmCategory.HARM_CATEGORY_HARASSMENT: generative_model.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
79
  }
80
  )
81
 
@@ -83,7 +83,7 @@ def generate(document_parts, prompt_text):
83
  model_service_client = ModelServiceClient()
84
  model_resource_name = model_service_client.model_path("akroda", "us-central1", "gemini-1.5-pro-001")
85
  response = model_service_client.generate_content(
86
- request=generative_model.GenerateContentRequest(
87
  model=model_resource_name,
88
  documents=document_parts,
89
  prompt=prompt_text,
 
2
  from pdfminer import high_level
3
  from langchain_core.prompts import PromptTemplate
4
  from google.cloud import aiplatform
5
+ from google.cloud.aiplatform_v1 import ModelServiceClient
6
+ from google.cloud.aiplatform_v1.types import GenerateContentRequest, Document, GenerationConfig, SafetySettings, HarmCategory, HarmBlockThreshold
7
  import base64
8
 
9
  # Initialize the Google AI Platform
 
11
 
12
  # Define the documents (base64-encoded PDF content)
13
  documents = [
14
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeODgxNz5dL1Jvb3QgMTU0IDAgUi9TaXplIDE2Nj4+CnN0YXJ0eHJlZgoyMTY0NjkKJSVFT0YK")),
15
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeLjz9MKNijU+PgpzdGFydHhyZWYKMTMxMDY0CiUlRU9GCg==")),
16
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeLjz9MKNiAwZDU0YTVlNzllMWRhYWY1ZDQ2YjI+XS9Sb290IDE3NyAwIFIvU2l6ZSAxODc+PgpzdGFydHhyZWYKMjA3NTk5CiUlRU9GCg==")),
17
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJeLjz9ML1Jvb3QgMTg5IDAgUi9TaXplIDE5OT4+CnN0YXJ0eHJlZgoxOTgzNzMKJSVFT0YK")),
18
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xCcnCmVuZHN0cmVhbQplbmRvYmoKc3RhcnR4cmVmCjIwOTgyNQolJUVPRgo=")),
19
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLj+CnN0YXJ0eHJlZgoyMTk5MDYKJSVFT0YK")),
20
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJiUlRU9GCg==")),
21
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjQKJe90IDMwOCAwIFIvU2l6ZSAzMTg+PgpzdGFydHhyZWYKMjcwNzU3CiUlRU9GCg==")),
22
+ Document(content_type="application/pdf", data=base64.b64decode("JVBERi0xLjUNJeLjz9MNCjcgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgNjc1NzgvTyA5L0UgNjAyNDYvTiAxL1QgNjcyODcvSCBbIDQ4MyAxNTRdPj4NZW5kb2JxDSAgICAgICAgICAgICAgICAgICAgDQoyMiAwIG9iag08PC9EZWNvZGVQYXJtczw8L0NvbHVtbnMgNC9QcmVkaWN0b3IgMTI+Pi9GaWx0ZXIvRmxhdGVEZWNvZGUvSURbPDE3NzU4MkJFODc4MzRFQjNBOEM3RkIzQTgyRjFFMEFCPjw5MzI2Qjk4REM4NjQ2RTRCODI3MzZFQUEzOENEQjFBQj5dL0luZGV4WzcgMjhdL0luZm8gNiAwIFIvTGVuZ3RoIDgzL1ByZXYgNjcyODgvUm9vdCA4IDAgUi9TaXplIDM1L1R5cGUvWFPRg0K"))
23
  ]
24
 
25
  text1 = """
 
64
  min_transaction_overdraft=min_transaction_overdraft,
65
  )
66
 
67
+ generation_config = GenerationConfig(
68
  max_output_tokens=8192,
69
  temperature=1,
70
  top_p=0.95,
71
  )
72
 
73
+ safety_settings = SafetySettings(
74
  harm_category_settings={
75
+ HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
76
+ HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
77
+ HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
78
+ HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
79
  }
80
  )
81
 
 
83
  model_service_client = ModelServiceClient()
84
  model_resource_name = model_service_client.model_path("akroda", "us-central1", "gemini-1.5-pro-001")
85
  response = model_service_client.generate_content(
86
+ request=GenerateContentRequest(
87
  model=model_resource_name,
88
  documents=document_parts,
89
  prompt=prompt_text,