Delete model.py
Browse files
model.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
from langchain_core.utils.function_calling import convert_to_openai_function
|
| 2 |
-
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 3 |
-
from langchain.memory import ConversationBufferWindowMemory
|
| 4 |
-
from langchain.schema.runnable import RunnablePassthrough
|
| 5 |
-
from langchain.agents.format_scratchpad import format_to_openai_functions
|
| 6 |
-
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
|
| 7 |
-
from langchain.agents import AgentExecutor
|
| 8 |
-
from langchain_groq import ChatGroq
|
| 9 |
-
from functions import book_slot , check_slots , suggest_specialization , reschedule_event,delete_event
|
| 10 |
-
|
| 11 |
-
def create_agent(general_prompt_template):
|
| 12 |
-
# print("get user Id**********************",user_id)
|
| 13 |
-
|
| 14 |
-
API_KEY = "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"
|
| 15 |
-
tools = [book_slot , delete_event , check_slots , suggest_specialization , reschedule_event]
|
| 16 |
-
functions = [convert_to_openai_function(f) for f in tools]
|
| 17 |
-
|
| 18 |
-
llm = ChatGroq(
|
| 19 |
-
model="llama-3.1-70b-versatile",
|
| 20 |
-
temperature=0,
|
| 21 |
-
max_tokens=None,
|
| 22 |
-
timeout=None,
|
| 23 |
-
max_retries=2,
|
| 24 |
-
api_key=API_KEY
|
| 25 |
-
).bind_functions(functions=functions)
|
| 26 |
-
|
| 27 |
-
prompt = ChatPromptTemplate.from_messages([("system", general_prompt_template),
|
| 28 |
-
MessagesPlaceholder(variable_name="chat_history"), ("user", "{input}"),
|
| 29 |
-
MessagesPlaceholder(variable_name="agent_scratchpad")])
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
memory = ConversationBufferWindowMemory(memory_key="chat_history" , return_messages=True, k=5)
|
| 34 |
-
|
| 35 |
-
chain = RunnablePassthrough.assign(agent_scratchpad=lambda x: format_to_openai_functions(x["intermediate_steps"])) | prompt | llm | OpenAIFunctionsAgentOutputParser()
|
| 36 |
-
|
| 37 |
-
agent_executor = AgentExecutor(
|
| 38 |
-
agent=chain, tools=tools, memory=memory, verbose=True)
|
| 39 |
-
|
| 40 |
-
return agent_executor
|
| 41 |
-
# give me available slots at 17 september 2024 , book schedule at 10:30 AM 17 september 2024 ,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|