Skip to content

Commit

Permalink
1. Optimize the keyword prompt
Browse files Browse the repository at this point in the history
2. Optimize Google search URL extraction

3. Abstract code logic, refactor search code

4. function call empty message does not enter message history
  • Loading branch information
yym68686 committed Nov 30, 2023
1 parent f357e54 commit 906bba2
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 98 deletions.
1 change: 0 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ async def button_press(update, context):
config.ChatGPTbot.reset(convo_id=str(update.effective_chat.id), system_prompt=config.systemprompt)
if config.ClaudeAPI and "claude" in data and not config.API:
config.ChatGPTbot = claudebot(api_key=f"{config.ClaudeAPI}", engine=config.GPT_ENGINE, system_prompt=config.systemprompt, temperature=config.temperature)
print(config.GPT_ENGINE)
try:
info_message = (
f"`Hi, {update.effective_user.username}!`\n\n"
Expand Down
6 changes: 5 additions & 1 deletion test/test_Web_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ def Web_crawler(url: str) -> str:
# for url in ['https://www.lifewire.com/403-forbidden-error-explained-2617989']:
# for url in ['https://www.usnews.com/news/best-countries/articles/2022-02-24/explainer-why-did-russia-invade-ukraine']:
# for url in ['https://github.com/EAimTY/tuic/issues/107']:
for url in ['https://mp.weixin.qq.com/s/Itad7Y-QBcr991JkF3SrIg']:
# TODO 没办法访问
# for url in ['https://s.weibo.com/top/summary?cate=realtimehot']:
# for url in ['https://tophub.today/n/KqndgxeLl9']:
for url in ['https://support.apple.com/zh-cn/HT213931']:
# for url in ['https://mp.weixin.qq.com/s/Itad7Y-QBcr991JkF3SrIg']:
# for url in ['https://zhidao.baidu.com/question/317577832.html']:
# for url in ['https://www.cnn.com/2023/09/06/tech/huawei-mate-60-pro-phone/index.html']:
# for url in ['https://www.reddit.com/r/China_irl/comments/15qojkh/46%E6%9C%88%E5%A4%96%E8%B5%84%E5%AF%B9%E4%B8%AD%E5%9B%BD%E7%9B%B4%E6%8E%A5%E6%8A%95%E8%B5%84%E5%87%8F87/', 'https://www.apple.com.cn/job-creation/Apple_China_CSR_Report_2020.pdf', 'https://hdr.undp.org/system/files/documents/hdr2013chpdf.pdf']:
Expand Down
40 changes: 31 additions & 9 deletions test/test_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,48 @@
from utils.googlesearch import GoogleSearchAPIWrapper


def getgooglesearchurl(result, numresults=3):
def getgooglesearchurl(result, numresults=1):
google_search = GoogleSearchAPIWrapper()
urls = []
googleresult = google_search.results(result, numresults)
urls = [i["link"] for i in googleresult]
# print("google urls", urls)
for i in googleresult:
if "No good Google Search Result was found" in i:
continue
urls.append(i["link"])
return urls

chainllm = ChatOpenAI(temperature=0.5, openai_api_base=os.environ.get('API_URL', None).split("chat")[0], model_name="gpt-4-1106-preview", openai_api_key=os.environ.get('API', None))
# keyword_prompt = PromptTemplate(
# input_variables=["source"],
# # template="*{source}*, ——我想通过网页搜索引擎,获取上述问题的可能答案。请你提取上述问题相关的关键词作为搜索用词(用空格隔开),直接给我结果(不要多余符号)。",
# template="根据我的问题,总结最少的关键词概括,用空格连接,不要出现其他符号,例如这个问题《How much does the 'zeabur' software service cost per month? Is it free to use? Any limitations?》,最小关键词是《zeabur price》,这是我的问题:{source}",
# # template="根据我的问题,仔细想想用什么样的搜索词更有可能搜索到答案,直接给我最好的搜索词,搜索词尽可能少,这是我的问题:{source}",
# # template="请你帮我抽取关键词,输出的关键词之间用空格连接。输出除了关键词,不用解释,也不要出现其他内容,只要出现关键词,必须用空格连接关键词,不要出现其他任何连接符。下面是要提取关键词的文字:{source}",
# )

keyword_prompt = PromptTemplate(
input_variables=["source"],
# template="*{source}*, ——我想通过网页搜索引擎,获取上述问题的可能答案。请你提取上述问题相关的关键词作为搜索用词(用空格隔开),直接给我结果(不要多余符号)。",
template="根据我的问题,总结最少的关键词概括,用空格连接,不要出现其他符号,例如这个问题《How much does the 'zeabur' software service cost per month? Is it free to use? Any limitations?》,最小关键词是《zeabur price》,这是我的问题:{source}",
# template="根据我的问题,仔细想想用什么样的搜索词更有可能搜索到答案,直接给我最好的搜索词,搜索词尽可能少,这是我的问题:{source}",
# template="请你帮我抽取关键词,输出的关键词之间用空格连接。输出除了关键词,不用解释,也不要出现其他内容,只要出现关键词,必须用空格连接关键词,不要出现其他任何连接符。下面是要提取关键词的文字:{source}",
template=(
"根据我的问题,总结最少的关键词概括,给出三行不同的关键词组合,每行的关键词用空格连接,至少有一行关键词里面有中文,至少有一行关键词里面有英文,不要出现其他符号。"
"下面是示例:"
"问题1:How much does the 'zeabur' software service cost per month? Is it free to use? Any limitations?"
"三行关键词是:"
"zeabur price"
"zeabur documentation"
"zeabur 价格"
"问题2:pplx API 怎么使用?"
"三行关键词是:"
"pplx API demo"
"pplx API"
"pplx API 使用方法"
"这是我的问题:{source}"
),
)
key_chain = LLMChain(llm=chainllm, prompt=keyword_prompt)
result = key_chain.run("奶茶妹妹什么时候跟刘强东结婚的?")
result = key_chain.run("今天的微博热搜有哪些?").split('\n')
# result = key_chain.run("鸿蒙是安卓套壳吗?")
# result = key_chain.run("How much does the 'zeabur' software service cost per month? Is it free to use? Any limitations?")
print(result)
# print(getgooglesearchurl("zeabur price"))
print(getgooglesearchurl(result))
for i in result:
print(getgooglesearchurl(i))
43 changes: 43 additions & 0 deletions test/test_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
os.system("clear")
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import config
import threading
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.chat_models import ChatOpenAI
from langchain.chat_models import ChatOpenAI

class ThreadWithReturnValue(threading.Thread):
def run(self):
if self._target is not None:
self._return = self._target(*self._args, **self._kwargs)

def join(self):
super().join()
return self._return


text = """
HomeReviewsAppleShould You Wait for the iPhone 15?Should You Install the Latest Version of iOS 16?iOS 16 ProblemsHow to Fix iOS 16 ProblemsThings the Apple Watch Can DoHow to Hide iPhone LocationAndroidBest Android Phones Under $200 (2023)Samsung Galaxy S22 ProblemsSamsung Galaxy Android 13 Update Info (2023)How ToHow to Fix iPhone 14 ProblemsHow to Fix iPhone 14 Battery Life ProblemsHow to Fix iPhone 14 Performance ProblemsGamingHow to Fix NBA 2K23 ProblemsBest Offline GamesEditor’s ChoiceAbout Connect with us Gotta Be Mobile5 Things to Know About the macOS Ventura 13.6.1 UpdateHomeReviewsAppleShould You Wait for the iPhone 15?Should You Install the Latest Version of iOS 16?iOS 16 ProblemsHow to Fix iOS 16 ProblemsThings the Apple Watch Can DoHow to Hide iPhone LocationAndroidBest Android Phones Under $200 (2023)Samsung Galaxy S22 ProblemsSamsung Galaxy Android 13 Update Info (2023)How ToHow to Fix iPhone 14 ProblemsHow to Fix iPhone 14 Battery Life ProblemsHow to Fix iPhone 14 Performance ProblemsGamingHow to Fix NBA 2K23 ProblemsBest Offline GamesEditor’s ChoiceAbout Apple5 Things to Know About the macOS Ventura 13.6.1 UpdatePublished 2 weeks ago on 11/16/2023By Adam Mills Apple’s pushed a brand new macOS Ventura 13.6.1 to Mac users.macOS Ventura 13.6.1 is a point release and it’s a small upgrade for Mac lingering on macOS Ventura. The software brings under-the-hood improvements to these devices.With that in mind, we want to take you through everything there you need to know about the latest macOS Ventura update for Mac.Table of ContentsmacOS Ventura 13.6.1 ReviewmacOS Ventura 13.6.1 ProblemsmacOS Ventura 13.6.1 FeaturesmacOS Ventura 13.6.1 DowngradeWhat’s NextWe’ll start out with some quick impressions regarding macOS Ventura 13.6.1 update’s performance.macOS Ventura 13.6.1 ReviewIf your Mac is currently running macOS Ventura 13.6, you’ll see a fairly small download. After the download, the installation should take around 10 or so minutes to complete.For more on the macOS Ventura 13.6.1 download and installation, take a look at our guide. It’ll walk you through everything you need to know before you install the new firmware on your Mac.We’ve been using the macOS Ventura 13.6.1 update on a MacBook Pro (2017) for several days now and performance is holding up nicely. Here’s what we’ve learned about its performance:macOS Ventura 13.6.1 Battery Life & ConnectivityBattery life is stable right now and we haven’t noticed any abnormal drainWi-Fi connectivity is currently fast and reliableBluetooth is working normallyApp PerformanceThird-party apps, including Twitter, Slack, Chrome, and Spotify are working properlyFirst party apps like Safari and Podcasts are also stable at the momentSpeedmacOS Ventura 13.6.1 feels fast and we haven’t noticed any UI lagIf your Mac is struggling on macOS Ventura 13.6 or an older version of macOS, you might want to install macOS Ventura 13.6.1 on your Mac right now.If you’re feeling leery, we’ve put together a list of the best reasons to, and not to, install the latest version of macOS Ventura on you Mac today.macOS Ventura 13.6.1 ProblemsApple tested macOS Ventura 13.6.1 for issues behind the scenes, but problems have unsurprisingly made their way into the public releaseWe haven’t noticed any major bugs or performance issues yet, but some users are complaining about performance issues and bugs.The current list of problems includes abnormal battery drain, Wi-Fi issues, Bluetooth problems, and problems with various first and third-party applications.If you run into issues on macOS Ventura 13.6.1, here are a few resources that could help.Before you get in touch with Apple’s customer support, have a look at our list of fixes for the most common macOS Ventura problems.If your Mac’s battery life is struggling after the upgrade, check out our fixes for macOS Ventura battery life problems.If you can’t find what you’re looking for in our guides, head over to Apple’s discussion forums. If the users there can’t help you, you might want to get in touch Apple customer support via the company’s website.If you still can’t fix your issue(s), you’ll probably want to schedule an appointment at your local Apple Store.macOS Ventura 13.6.1 FeaturesApple’s maintenance updates typically bring under-the-hood improvements to Mac devices and that’s exactly what macOS Ventura 13.6.1 brings to the table.The software doesn’t have any new features or bug fixes on board, but instead delivers security patches to Mac devices. You can learn more about the patches over on Apple’s security site.macOS Ventura 13.6.1 DowngradeIf you run into problems on macOS Ventura 13.6.1, you can try moving your Mac’s software back to an older version if you think it could help.If you’re interested in moving back to older software, have a look at our downgrade guide. It will help you get familiar with the process and make the move back.What’s NextIf your Mac is struggling on macOS Ventura 13.6.1 or an older version of macOS, you’ll be on your own for a bit.macOS Ventura 13.6.1 won’t be the last version of macOS Ventura, but it’s unclear when the next version will roll out to those still utilizing the operating system.We don’t expect Apple to bring new features to macOS Ventura down the line, but we do expect the company to continue offering security updates.These upgrades will probably roll out alongside new versions of macOS Sonoma so be on the lookout in the weeks ahead. The next version of macOS Sonoma should roll out in December.4 Reasons Not to Install macOS Ventura 13.6.1 & 11 Reasons You ShouldInstall macOS Ventura 13.6.1 for Better Security>1 / 15If you want to protect your Mac and its data from harm, you'll probably want to download the newest version of macOS Ventura.macOS Ventura 13.6.1's focus is on security and the firmware brings important security patches to Macs. The software patches up issues with FindMy, PassKeys, and more.As for older updates, Apple's macOS Ventura 13.6 update had a trio of security patches on board. If you're interested in the particulars, check out the company's security site.macOS Ventura 13.5.2 brought one security patch with it and it was an important one. If you want more information about the fix, head over to Apple.macOS Ventura 13.5 brought 29 security patches to Mac. To learn more about these patches, head over to Apple's website. macOS Ventura 13.4.1 had two essential security patches on board. If you want to learn more about them, head on over to Apple's website.Apple's macOS Security Response 13.4.1 (c) update also included a security update and you can learn more about it right here.macOS Ventura 13.4 had numerous security updates on board and you can read more about them on Apple's security site.macOS Ventura 13.3.1 patched up two actively exploited vulnerabilities which made it an important download. You can learn about the two patches right here.The macOS Ventura 13.3 update brought numerous security patches to Macs. If you want to learn more about these changes, check out Apple's guide.macOS Ventura 13.2.1 brought four security patches to compatible Mac models. You can read more about those over on Apple's security site.The macOS Ventura 13.2 update brought 25 security patches to Mac devices. You can read about those right here.In addition, the software came with support for physical security keys for Apple ID. These will beef up your account security by requiring a physical security key as part of the two factor authentication sign in process. Learn more about the change right here.macOS Ventura 13.1 delivered 35 security patches and it also brought upgrades to Advanced Data Protection for iCloud.macOS Ventura 13.0.1 brought two security patches and the first version of macOS Ventura, macOS Ventura 13.0, had a ton of patches on board. >1 / 15Related Topics:AppleMacBookMacBook PromacOSmacOS VenturamacOS Ventura 13.6.1macOS Ventura 13.6.1 changesmacOS Ventura 13.6.1 featuresmacOS Ventura 13.6.1 issuesmacOS Ventura 13.6.1 performancemacOS Ventura 13.6.1 problemsmacOS Ventura 13.6.1 reviewmacOS Ventura 13.6.1 reviewsmacOS Ventura 13.6.1 softwaremacOS Ventura 13.6.1 updatemacOS Ventura 13.6.1 upgradeSoftwareTechnologyClick to commentLeave a Reply Cancel replyYour email address will not be published. Required fields are marked *Comment * Name * Email * Website Save my name, email, and website in this browser for the next time I comment. Δ As an Amazon Associate I earn from qualifying purchases. Privacy Policy Copyright © 2023 SXL Media Group, Inc.
"""

summary_prompt = PromptTemplate(
input_variables=["web_summary", "question", "language"],
template=(
"You need to response the following question: {question}."
"Your task is answer the above question in {language} based on the Search results provided."
"Search results: {web_summary}."
# "If there is no relevant content in the search results, just answer None, do not make any explanations."
),
)
chainllm = ChatOpenAI(temperature=config.temperature, openai_api_base=config.bot_api_url.v1_url, model_name=config.GPT_ENGINE, openai_api_key=config.API)

chain = LLMChain(llm=chainllm, prompt=summary_prompt)

# result = chain.run({"web_summary": text, "question": "macos 13.6 有什么新功能", "language": config.LANGUAGE})
chain_thread = ThreadWithReturnValue(target=chain.run, args=({"web_summary": text, "question": "macos 13.6 有什么新功能", "language": config.LANGUAGE},))
chain_thread.start()
result = chain_thread.join()
print(result)
Loading

0 comments on commit 906bba2

Please sign in to comment.