File size: 1,684 Bytes
d037cdf
 
 
 
 
 
 
4a65fd2
 
a4b89be
 
d037cdf
 
 
 
 
 
 
a4b89be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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