Update main.py
Browse files
main.py
CHANGED
@@ -19,7 +19,7 @@ app.add_middleware( # add the middleware
|
|
19 |
|
20 |
google_api_key = os.environ["GOOGLE_API_KEY"]
|
21 |
cse_id = os.environ["GOOGLE_CSE_ID"]
|
22 |
-
|
23 |
|
24 |
def search_google(query):
|
25 |
service = build("customsearch", "v1", developerKey=google_api_key)
|
@@ -35,15 +35,20 @@ def hello():
|
|
35 |
return "Hello! My name is Linlada."
|
36 |
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
def gpt_with_google_search(prompt):
|
40 |
search_results = search_google(prompt)
|
41 |
text = ""
|
42 |
ref = ""
|
43 |
for item in search_results:
|
44 |
text += item['title'] + "\n" + item['snippet'] + "\n\n"
|
45 |
ref += "- {} ({})\n".format(item['title'], item['link'])
|
46 |
-
results =
|
47 |
res = "{} \n\n {}".format(results, ref)
|
48 |
return res
|
49 |
|
@@ -63,8 +68,7 @@ def gpt_with_google_search(prompt):
|
|
63 |
class Linlada(BaseModel):
|
64 |
prompt: str
|
65 |
web_access: str = True
|
66 |
-
model: str =
|
67 |
-
|
68 |
|
69 |
|
70 |
@app.post('/linlada')
|
@@ -72,11 +76,10 @@ def linlada(request: Linlada):
|
|
72 |
prompt = request.prompt
|
73 |
model = request.model
|
74 |
web_access = request.web_access
|
75 |
-
llm = G4F(model=model)
|
76 |
if web_access == "True":
|
77 |
-
chat = gpt_with_google_search(prompt)
|
78 |
else:
|
79 |
-
chat = llm(prompt)
|
80 |
return chat
|
81 |
|
82 |
|
|
|
19 |
|
20 |
google_api_key = os.environ["GOOGLE_API_KEY"]
|
21 |
cse_id = os.environ["GOOGLE_CSE_ID"]
|
22 |
+
|
23 |
|
24 |
def search_google(query):
|
25 |
service = build("customsearch", "v1", developerKey=google_api_key)
|
|
|
35 |
return "Hello! My name is Linlada."
|
36 |
|
37 |
|
38 |
+
def llm(prompt, model):
|
39 |
+
llm = G4F(model=model)
|
40 |
+
response = llm(prompt)
|
41 |
+
return response
|
42 |
+
|
43 |
|
44 |
+
def gpt_with_google_search(prompt, model):
|
45 |
search_results = search_google(prompt)
|
46 |
text = ""
|
47 |
ref = ""
|
48 |
for item in search_results:
|
49 |
text += item['title'] + "\n" + item['snippet'] + "\n\n"
|
50 |
ref += "- {} ({})\n".format(item['title'], item['link'])
|
51 |
+
results = llm(prompt = f'Summarize: {text}', model = model)
|
52 |
res = "{} \n\n {}".format(results, ref)
|
53 |
return res
|
54 |
|
|
|
68 |
class Linlada(BaseModel):
|
69 |
prompt: str
|
70 |
web_access: str = True
|
71 |
+
model: str = os.environ['default_model']
|
|
|
72 |
|
73 |
|
74 |
@app.post('/linlada')
|
|
|
76 |
prompt = request.prompt
|
77 |
model = request.model
|
78 |
web_access = request.web_access
|
|
|
79 |
if web_access == "True":
|
80 |
+
chat = gpt_with_google_search(prompt, model)
|
81 |
else:
|
82 |
+
chat = llm(prompt, model)
|
83 |
return chat
|
84 |
|
85 |
|