pazukdev commited on
Commit
ff3e25d
·
verified ·
1 Parent(s): 81db50e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -9,15 +9,27 @@ from langchain.agents import AgentExecutor, create_openai_functions_agent
9
  from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
10
  from langchain_core.messages import AIMessage, HumanMessage
11
  from langchain.tools import StructuredTool
12
- from gptcache import cache
13
- from gptcache.adapter.langchain_models import LangChainLLMs
14
 
15
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
16
 
17
- def get_content_func(data, **_):
18
- return data.get("prompt").split("Question")[-1]
19
 
20
- cache.init(pre_embedding_func=get_content_func)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  cache.set_openai_key()
22
 
23
  def repo_get_all_employees_from_database():
@@ -78,8 +90,8 @@ class GetEmployees(BaseModel):
78
  start_time: str = Field(..., description="Required start time")
79
  duration_hours: int = Field(..., description="Required duration of the availability in hours")
80
 
81
- # llm = ChatOpenAI(temperature=1.0, model_name="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY)
82
- llm = LangChainLLMs(llm=ChatOpenAI(temperature=1.0, model_name="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY))
83
 
84
  tools = [
85
  StructuredTool.from_function(
 
9
  from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
10
  from langchain_core.messages import AIMessage, HumanMessage
11
  from langchain.tools import StructuredTool
 
 
12
 
13
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
14
 
15
+ def response_text(openai_resp):
16
+ return openai_resp['choices'][0]['message']['content']
17
 
18
+ from gptcache import cache
19
+ from gptcache.adapter import openai
20
+ from gptcache.embedding import Onnx
21
+ from gptcache.manager import CacheBase, VectorBase, get_data_manager
22
+ from gptcache.similarity_evaluation.distance import SearchDistanceEvaluation
23
+
24
+ print("Cache loading.....")
25
+
26
+ onnx = Onnx()
27
+ data_manager = get_data_manager(CacheBase("sqlite"), VectorBase("faiss", dimension=onnx.dimension))
28
+ cache.init(
29
+ embedding_func=onnx.to_embeddings,
30
+ data_manager=data_manager,
31
+ similarity_evaluation=SearchDistanceEvaluation(),
32
+ )
33
  cache.set_openai_key()
34
 
35
  def repo_get_all_employees_from_database():
 
90
  start_time: str = Field(..., description="Required start time")
91
  duration_hours: int = Field(..., description="Required duration of the availability in hours")
92
 
93
+ llm = ChatOpenAI(temperature=1.0, model_name="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY)
94
+ # llm = LangChainLLMs(llm=ChatOpenAI(temperature=1.0, model_name="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY))
95
 
96
  tools = [
97
  StructuredTool.from_function(