randydev commited on
Commit
21a37fb
1 Parent(s): 8e64de4

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +38 -1
main.py CHANGED
@@ -526,7 +526,7 @@ def free_chatgpt4_bing(query: str):
526
  return {"status": "false", "message": "Error response."}
527
 
528
  @app.post("/ryuzaki/google-ai")
529
- def google_ai(query: str, api_key: None = Depends(validate_api_key)):
530
  url = SOURCE_ASSISTANT_GOOGLE_AI
531
  token = ASSISTANT_GOOGLE_API_KEYS
532
  api_url = f"{SOURCE_ASSISTANT_GOOGLE_AI}/v1beta3/models/text-bison-001:generateText?key={ASSISTANT_GOOGLE_API_KEYS}"
@@ -551,6 +551,43 @@ def google_ai(query: str, api_key: None = Depends(validate_api_key)):
551
  except:
552
  return {"status": "false", "message": "Error response."}
553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  async def get_data(username):
555
  base_msg = ""
556
  async with AsyncClient() as gpx:
 
526
  return {"status": "false", "message": "Error response."}
527
 
528
  @app.post("/ryuzaki/google-ai")
529
+ def v1beta3_google_ai(query: str, api_key: None = Depends(validate_api_key)):
530
  url = SOURCE_ASSISTANT_GOOGLE_AI
531
  token = ASSISTANT_GOOGLE_API_KEYS
532
  api_url = f"{SOURCE_ASSISTANT_GOOGLE_AI}/v1beta3/models/text-bison-001:generateText?key={ASSISTANT_GOOGLE_API_KEYS}"
 
551
  except:
552
  return {"status": "false", "message": "Error response."}
553
 
554
+ @app.post("/ryuzaki/v1beta2-google-ai")
555
+ def v1beta2_google_ai(
556
+ query: str,
557
+ temperature=0.5,
558
+ candidateCount=1,
559
+ api_key: None = Depends(validate_api_key)
560
+ ):
561
+ url = SOURCE_ASSISTANT_GOOGLE_AI
562
+ token = ASSISTANT_GOOGLE_API_KEYS
563
+ api_url = f"{SOURCE_ASSISTANT_GOOGLE_AI}/v1beta2/models/text-bison-001:generateMessage?key={ASSISTANT_GOOGLE_API_KEYS}"
564
+ try:
565
+ headers = {"Content-Type": "application/json"}
566
+ data = {
567
+ "prompt": {
568
+ "messages": [
569
+ {
570
+ "content": query
571
+ }
572
+ ]
573
+ },
574
+ "temperature": temperature,
575
+ "candidateCount": candidateCount
576
+ }
577
+ response = requests.post(api_url, headers=headers, json=data)
578
+ response_str = response.json()
579
+ answer = response_str["candidates"]
580
+ for results in answer:
581
+ message = results.get("content")
582
+ return {
583
+ "status": "true",
584
+ "randydev":{
585
+ "message": message
586
+ }
587
+ }
588
+ except:
589
+ return {"status": "false", "message": "Error response."}
590
+
591
  async def get_data(username):
592
  base_msg = ""
593
  async with AsyncClient() as gpx: