Spaces:
Runtime error
Runtime error
远兮
commited on
Commit
·
ec64cd3
1
Parent(s):
85a9c6b
adb track usage
Browse files- README.md +4 -0
- faiss.index +0 -0
- llms_cache_gpt_similarity.py +4 -6
- openai_agent.py +9 -1
- openai_track_usage.ipynb +69 -0
- sqlite.db +0 -0
README.md
CHANGED
@@ -41,4 +41,8 @@ pip3 install --upgrade langchain
|
|
41 |
查看安装列表及版本:
|
42 |
pip3 list
|
43 |
|
|
|
|
|
|
|
|
|
44 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
41 |
查看安装列表及版本:
|
42 |
pip3 list
|
43 |
|
44 |
+
TODO:
|
45 |
+
1.看一下ONNXruntime
|
46 |
+
2.详细看一下gptcache
|
47 |
+
|
48 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
faiss.index
CHANGED
Binary files a/faiss.index and b/faiss.index differ
|
|
llms_cache_gpt_similarity.py
CHANGED
@@ -13,8 +13,8 @@ from gptcache.similarity_evaluation.distance import SearchDistanceEvaluation
|
|
13 |
llm = OpenAI(model_name="text-davinci-003")
|
14 |
|
15 |
# Avoid multiple caches using the same file, causing different llm model caches to affect each other
|
16 |
-
i =
|
17 |
-
file_prefix = "
|
18 |
llm_cache = Cache()
|
19 |
|
20 |
|
@@ -33,10 +33,8 @@ def init_gptcache_map(cache_obj: gptcache.Cache):
|
|
33 |
)
|
34 |
i += 1
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
%%time
|
39 |
-
for i in range(20):
|
40 |
start = time.perf_counter()
|
41 |
prompt = "男生有2人,女生有{:d}人,一共多少人?".format(i)
|
42 |
print("男生有2人,女生有{:d}人, {:s}。 suspend: {:0.4f}".format(i, llm(prompt), time.perf_counter() - start))
|
|
|
13 |
llm = OpenAI(model_name="text-davinci-003")
|
14 |
|
15 |
# Avoid multiple caches using the same file, causing different llm model caches to affect each other
|
16 |
+
i = 1
|
17 |
+
file_prefix = "data_onnx"
|
18 |
llm_cache = Cache()
|
19 |
|
20 |
|
|
|
33 |
)
|
34 |
i += 1
|
35 |
|
36 |
+
for i in range(50):
|
37 |
+
langchain.llm_cache = GPTCache(init_gptcache_map)
|
|
|
|
|
38 |
start = time.perf_counter()
|
39 |
prompt = "男生有2人,女生有{:d}人,一共多少人?".format(i)
|
40 |
print("男生有2人,女生有{:d}人, {:s}。 suspend: {:0.4f}".format(i, llm(prompt), time.perf_counter() - start))
|
openai_agent.py
CHANGED
@@ -2,6 +2,7 @@ from langchain.agents import load_tools
|
|
2 |
from langchain.agents import initialize_agent
|
3 |
from langchain.agents import AgentType
|
4 |
from langchain.llms import OpenAI
|
|
|
5 |
|
6 |
# First, let's load the language model we're going to use to control the agent.
|
7 |
llm = OpenAI(temperature=0)
|
@@ -14,4 +15,11 @@ tools = load_tools(["serpapi", "llm-math"], llm=llm)
|
|
14 |
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
15 |
|
16 |
# Now let's test it out!
|
17 |
-
agent.run("昨天北京气温如何?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from langchain.agents import initialize_agent
|
3 |
from langchain.agents import AgentType
|
4 |
from langchain.llms import OpenAI
|
5 |
+
from langchain.callbacks import get_openai_callback
|
6 |
|
7 |
# First, let's load the language model we're going to use to control the agent.
|
8 |
llm = OpenAI(temperature=0)
|
|
|
15 |
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
16 |
|
17 |
# Now let's test it out!
|
18 |
+
agent.run("昨天北京气温如何?")
|
19 |
+
|
20 |
+
with get_openai_callback() as cb:
|
21 |
+
response = agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?")
|
22 |
+
print(f"Total Tokens: {cb.total_tokens}")
|
23 |
+
print(f"Prompt Tokens: {cb.prompt_tokens}")
|
24 |
+
print(f"Completion Tokens: {cb.completion_tokens}")
|
25 |
+
print(f"Total Cost (USD): ${cb.total_cost}")
|
openai_track_usage.ipynb
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 20,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"from langchain.llms import OpenAI\n",
|
10 |
+
"from langchain.callbacks import get_openai_callback"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 21,
|
16 |
+
"metadata": {},
|
17 |
+
"outputs": [],
|
18 |
+
"source": [
|
19 |
+
"llm = OpenAI(model_name=\"text-davinci-002\", temperature=0)"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 22,
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [
|
27 |
+
{
|
28 |
+
"name": "stdout",
|
29 |
+
"output_type": "stream",
|
30 |
+
"text": [
|
31 |
+
"Tokens Used: 56\n",
|
32 |
+
"\tPrompt Tokens: 44\n",
|
33 |
+
"\tCompletion Tokens: 12\n",
|
34 |
+
"Successful Requests: 2\n",
|
35 |
+
"Total Cost (USD): $0.0011200000000000001\n"
|
36 |
+
]
|
37 |
+
}
|
38 |
+
],
|
39 |
+
"source": [
|
40 |
+
"with get_openai_callback() as suspend:\n",
|
41 |
+
" llm(\"男生3人,女生2人,老师有1人,一共多少人?\")\n",
|
42 |
+
" llm(\"33*2=?\")\n",
|
43 |
+
" print(suspend)"
|
44 |
+
]
|
45 |
+
}
|
46 |
+
],
|
47 |
+
"metadata": {
|
48 |
+
"kernelspec": {
|
49 |
+
"display_name": "base",
|
50 |
+
"language": "python",
|
51 |
+
"name": "python3"
|
52 |
+
},
|
53 |
+
"language_info": {
|
54 |
+
"codemirror_mode": {
|
55 |
+
"name": "ipython",
|
56 |
+
"version": 3
|
57 |
+
},
|
58 |
+
"file_extension": ".py",
|
59 |
+
"mimetype": "text/x-python",
|
60 |
+
"name": "python",
|
61 |
+
"nbconvert_exporter": "python",
|
62 |
+
"pygments_lexer": "ipython3",
|
63 |
+
"version": "3.10.10"
|
64 |
+
},
|
65 |
+
"orig_nbformat": 4
|
66 |
+
},
|
67 |
+
"nbformat": 4,
|
68 |
+
"nbformat_minor": 2
|
69 |
+
}
|
sqlite.db
CHANGED
Binary files a/sqlite.db and b/sqlite.db differ
|
|