-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (43 loc) · 1.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from langchain_community.chat_models import ChatOpenAI
from langchain_google_genai import (
ChatGoogleGenerativeAI,
HarmBlockThreshold,
HarmCategory,
)
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import os
from dotenv import load_dotenv
load_dotenv()
def main(model=None, u_question=None):
prompt_template = """
Answer the question as detailed as possible.
Question: \n{question}\n
Answer:
"""
if model == "open-ai":
api_key = os.getenv("OPENAI_API_KEY")
llm = ChatOpenAI(api_key=api_key)
prompt = PromptTemplate(template=prompt_template, input_variables=["question"])
llm_chain = prompt | llm
response = llm_chain.invoke({'question':u_question})
return response
elif model == "gemini-pro":
api_key = os.getenv("GOOGLE_API_KEY")
llm = ChatGoogleGenerativeAI(
model="gemini-pro",
temperature=0.3,
google_api_key=api_key,
safety_settings={
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
},)
prompt = PromptTemplate(template=prompt_template, input_variables=[ "question"])
llm_chain = prompt | llm
response = llm_chain.invoke({'question':u_question})
return response.content
if __name__ == "__main__":
question = """How can AI and machine learning be integrated into
microservices architecture to improve scalability and reliability in telecom systems?
"""
response = main(model="gemini-pro", u_question=question)
print (response)