galactromedaNPMAIECOSYSTEM commited on
Commit
d5313bc
·
verified ·
1 Parent(s): 658fe13

Upload main.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. main.py +34 -0
main.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ from tavily import TavilyClient
5
+ from datetime import date
6
+ from langchain_ollama.llms import OllamaLLM
7
+
8
+ app = FastAPI()
9
+
10
+ class PromptRequest(BaseModel):
11
+ prompt: str
12
+ temperature: float = 0.5
13
+
14
+ @app.get("/")
15
+ def health():
16
+ return {"ok": True}
17
+
18
+ today_date = date.today()
19
+
20
+ def search_tool(query:str):
21
+ api_key = os.environ.get("TAVILY_API_KEY")
22
+ client = TavilyClient(api_key)
23
+ response = client.search(query=query, include_answer="advanced", search_depth="advanced")
24
+ return response
25
+
26
+ @app.post("/vicuna:7b")
27
+ async def generate_response(request: PromptRequest):
28
+ llm = OllamaLLM(
29
+ model="vicuna:7b",
30
+ temperature=request.temperature,
31
+ base_url="http://localhost:11434"
32
+ )
33
+ response = llm.invoke(request.prompt)
34
+