Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ import json
|
|
18 |
import chainlit as cl
|
19 |
from dotenv import load_dotenv
|
20 |
|
21 |
-
from pydantic import BaseModel
|
22 |
|
23 |
from langchain import hub
|
24 |
from langchain_openai import OpenAI
|
@@ -39,6 +39,7 @@ load_dotenv()
|
|
39 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
40 |
auth_token = os.getenv("DAYSOFF_API_TOKEN")
|
41 |
|
|
|
42 |
class EnhancedRequestsPostTool(RequestsPostTool, BaseModel):
|
43 |
url_chain: LLMChain
|
44 |
response_chain: LLMChain
|
@@ -49,8 +50,22 @@ class EnhancedRequestsPostTool(RequestsPostTool, BaseModel):
|
|
49 |
object.__setattr__(self, 'url_chain', LLMChain(llm=llm, prompt=api_url_prompt)) # object.__setattr__ (’set attribute’, i.e error with "fields")
|
50 |
object.__setattr__(self, 'response_chain', LLMChain(llm=llm, prompt=api_response_prompt))
|
51 |
object.__setattr__(self, 'api_docs', api_docs)
|
|
|
|
|
|
|
|
|
52 |
|
|
|
|
|
|
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
async def ainvoke(self, input_data, callbacks=None):
|
55 |
# -- create API URL
|
56 |
url_response = await self.url_chain.ainvoke({
|
|
|
18 |
import chainlit as cl
|
19 |
from dotenv import load_dotenv
|
20 |
|
21 |
+
from pydantic import BaseModel, PrivateAttr
|
22 |
|
23 |
from langchain import hub
|
24 |
from langchain_openai import OpenAI
|
|
|
39 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
40 |
auth_token = os.getenv("DAYSOFF_API_TOKEN")
|
41 |
|
42 |
+
"""
|
43 |
class EnhancedRequestsPostTool(RequestsPostTool, BaseModel):
|
44 |
url_chain: LLMChain
|
45 |
response_chain: LLMChain
|
|
|
50 |
object.__setattr__(self, 'url_chain', LLMChain(llm=llm, prompt=api_url_prompt)) # object.__setattr__ (’set attribute’, i.e error with "fields")
|
51 |
object.__setattr__(self, 'response_chain', LLMChain(llm=llm, prompt=api_response_prompt))
|
52 |
object.__setattr__(self, 'api_docs', api_docs)
|
53 |
+
"""
|
54 |
+
|
55 |
+
class EnhancedRequestsPostTool(RequestsPostTool, BaseModel):
|
56 |
+
api_docs: str # --api_docs:field up for validtn.
|
57 |
|
58 |
+
# --PrivateAttr@dynanmc init attrbts
|
59 |
+
url_chain: LLMChain = PrivateAttr()
|
60 |
+
response_chain: LLMChain = PrivateAttr()
|
61 |
|
62 |
+
def __init__(self, requests_wrapper, llm, api_docs, api_url_prompt, api_response_prompt):
|
63 |
+
super().__init__(requests_wrapper=requests_wrapper, allow_dangerous_requests=True)
|
64 |
+
self.api_docs = api_docs # --init field
|
65 |
+
self.url_chain = LLMChain(llm=llm, prompt=api_url_prompt) # --dynanmc init1
|
66 |
+
self.response_chain = LLMChain(llm=llm, prompt=api_response_prompt) # --dynanmc init2
|
67 |
+
|
68 |
+
|
69 |
async def ainvoke(self, input_data, callbacks=None):
|
70 |
# -- create API URL
|
71 |
url_response = await self.url_chain.ainvoke({
|