Spaces:
Runtime error
Runtime error
| from langchain.chains import LLMChain | |
| from langchain.prompts.chat import ( | |
| ChatPromptTemplate, | |
| SystemMessagePromptTemplate, | |
| HumanMessagePromptTemplate) | |
| from chains.azure_openai import CustomAzureOpenAI | |
| from prompts.summary import system_template, human_template | |
| from config import OPENAI_API_TYPE, OPENAI_API_VERSION, OPENAI_API_KEY, OPENAI_API_BASE, DEPLOYMENT_ID, API_KEY | |
| from langchain.chat_models import ChatOpenAI | |
| import json | |
| import requests | |
| class WebSummary(LLMChain): | |
| prompt = ChatPromptTemplate.from_messages( | |
| [SystemMessagePromptTemplate.from_template( | |
| system_template), | |
| HumanMessagePromptTemplate.from_template(human_template) | |
| ]) | |
| llm = CustomAzureOpenAI(deployment_name=DEPLOYMENT_ID, | |
| openai_api_type=OPENAI_API_TYPE, | |
| openai_api_base=OPENAI_API_BASE, | |
| openai_api_version=OPENAI_API_VERSION, | |
| openai_api_key=OPENAI_API_KEY, | |
| temperature=0.0) | |
| def run(self, question, num_result=4): | |
| params = { | |
| "q": question, | |
| "v": "\{539C9DC1-663A-418D-82A4-662D34EE34BC\}", | |
| "p": 10, | |
| "l": "en", | |
| "s": "{EACE8DB5-668F-4357-9782-405070D28D11}", | |
| "itemid": "\{91F4101E-B1F3-4905-A832-96F703D3FBB1\}", | |
| } | |
| req = requests.get( | |
| "https://fptsoftware.com//sxa/search/results/?", | |
| params=params | |
| ) | |
| res = json.loads(req.text) | |
| results = [] | |
| for r in res["Results"][:num_result]: | |
| link = "https://fptsoftware.com" + r["Url"] | |
| results.append({"link": link}) | |
| return results |