Spaces:
Runtime error
Runtime error
File size: 7,161 Bytes
2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 dccc64a 2ef1d57 |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from langchain.llms import OpenAI\n",
"from langchain.chains import LLMRequestsChain, LLMChain"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from langchain.prompts import PromptTemplate\n",
"\n",
"template = \"\"\"Between >>> and <<< are the raw search result text from google.\n",
"Extract the answer to the question '{query}' or say \"not found\" if the information is not contained.\n",
"Use the format\n",
"Extracted:<answer or \"not found\">\n",
">>> {requests_result} <<<\n",
"Extracted:\"\"\"\n",
"\n",
"PROMPT = PromptTemplate(\n",
" input_variables=[\"query\", \"requests_result\"],\n",
" template=template,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"chain = LLMRequestsChain(llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=PROMPT))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"question = \"今天是日期是?\"\n",
"inputs = {\n",
" \"query\": question,\n",
" \"url\": \"https://www.google.com/search?q=\" + question.replace(\" \", \"+\")\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'query': '今天是日期是?',\n",
" 'url': 'https://www.google.com/search?q=今天是日期是?',\n",
" 'output': '2023年5月6日星期六'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain(inputs)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'query': '执行decode后,找出所有中文',\n",
" 'url': 'https://i.zuoyebang.cc/odsv2/#/admin/weekly-stats',\n",
" 'output': ' not found'}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"question = \"执行decode后,找出所有中文\"\n",
"inputs = {\n",
" \"query\": question,\n",
" \"url\": \"https://i.zuoyebang.cc/odsv2/#/admin/weekly-stats\"\n",
"}\n",
"chain(inputs)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'<!DOCTYPE html><html lang=\"zh\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><meta name=\"theme-color\" content=\"#028bff\" media=\"(prefers-color-scheme: light)\"><link rel=\"icon\" href=\"//www.zuoyebang.cc/favicon.ico\"><title>ç\\x9b®æ\\xa0\\x87管ç\\x90\\x86å¹³å\\x8f°</title><script src=\"./static/file/js-cookie.js\"></script><script>// (function() {\\n // var Cookies = window.Cookies;\\n // if (Cookies) {\\n // if (Cookies.get(\\'odsv2\\') === \\'0\\' && window.location.href.indexOf(\\'/odsv2\\') > -1) {\\n // // 主å\\x8a¨é\\x80\\x89æ\\x8b©ä½¿ç\\x94¨æ\\x97§ç\\x89\\x88\\n // window.location.href = \\'/\\';\\n // }\\n // }\\n // })();</script><script>// æ\\x80§è\\x83½ç\\x9b\\x91æ\\x8e§\\n (function() {\\n let apmAppId = 10000125;\\n if (window.location.host.indexOf(\\'zuoyebang.cc\\') > -1) {\\n // 线ä¸\\x8a\\n apmAppId = 10000122;\\n }\\n window.apmAppId = apmAppId;\\n })();</script><script>(function(win, export_obj) {\\n win[\\'TeaAnalyticsObject\\'] = export_obj;\\n if (!win[export_obj]) {\\n function _collect() {\\n _collect.q.push(arguments);\\n }\\n _collect.q = _collect.q || [];\\n win[export_obj] = _collect;\\n }\\n win[export_obj].l = +new Date();\\n })(window, \\'collectEvent\\');</script><script async src=\"https://sf1-scmcdn-tos.pstatp.com/goofy/log-sdk/collect/collect-autotrack-rangers-v4.1.49.js\"></script><script>if (!window.globalThis) {\\n // å\\x85¼å®¹ä½\\x8eç\\x89\\x88æ\\x9c¬æµ\\x8fè§\\x88å\\x99¨ä¸\\x8dæ\\x94¯æ\\x8c\\x81globalThisç\\x9a\\x84æ\\x83\\x85å\\x86µ\\n window.globalThis = window;\\n }</script><script>(function() {\\n // dataFinder\\n window.collectEvent(\\'init\\', {\\n app_id: window.apmAppId,\\n channel_domain: \\'https://apm.zuoyebang.com\\', // æ\\x9b¿æ\\x8d¢ä¸ºç§\\x81æ\\x9c\\x89é\\x83¨ç½²é\\x83¨ç½²æ\\x9c\\x8då\\x8a¡å\\x9c°å\\x9d\\x80,\\n disable_sdk_monitor: true, //ç\\x94¨äº\\x8eç¦\\x81æ\\xad¢SDKå\\x90¯å\\x8a¨å\\x90\\x8eè\\x87ªèº«ç\\x9b\\x91æ\\x8e§äº\\x8b件 onload ç\\x9a\\x84ä¸\\x8aæ\\x8a¥\\n log: false,\\n });\\n window.collectEvent(\\'start\\');\\n\\n // apmInsight\\n // window.RangersSiteSDK(\"config\", {\\n // app_id: window.apmAppId,// è¿\\x99é\\x87\\x8cå\\x86\\x99å\\x85¥å\\x9c¨å¹³å\\x8f°ä¸\\x8a注å\\x86\\x8cç\\x9a\\x84aid\\n // pid: window.location.href,\\n // // user_unique_id: \\'\\',\\n // serverDomain: \\'https://apm.zuoyebang.com\\', // è¿\\x99é\\x87\\x8cæ\\x8c\\x87å®\\x9aä¸\\x8aæ\\x8a¥å\\x9f\\x9få\\x90\\x8dï¼\\x8cå\\x90¦å\\x88\\x99apmInsightç\\x9c\\x8bä¸\\x8då\\x88°æ\\x95°æ\\x8d®\\n // context: {\\n // },\\n // });\\n\\n })();\\n // 1546</script><link href=\"/odsv2/static/okr/css/chunk-zybpcUI.87bd49cd.css\" rel=\"stylesheet\"><link href=\"/odsv2/static/okr/css/chunk-libs.cf218c77.css\" rel=\"stylesheet\"><link href=\"/odsv2/static/okr/css/okr-app.e9bf765d.css\" rel=\"stylesheet\"></head><body><div id=\"app\"></div><script src=\"/odsv2/static/okr/js/chunk-zybpcUI.104a0d08.js\"></script><script src=\"/odsv2/static/okr/js/chunk-libs.455ada3e.js\"></script><script src=\"/odsv2/static/okr/js/okr-app.5924badf.js\"></script></body><script>window._codeVersion=\\'1546\\';</script></html>'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain.utilities import TextRequestsWrapper\n",
"requests = TextRequestsWrapper()\n",
"requests.get(\"https://i.zuoyebang.cc/odsv2/#/admin/weekly-stats\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|