8000 Add clients example. Closes #46 · coderonion/llama-cpp-python@6d1bda4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d1bda4

Browse files
committed
Add clients example. Closes abetlen#46
1 parent c940193 commit 6d1bda4

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

examples/notebooks/Clients.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"data": {
10+
"text/plain": [
11+
"<OpenAIObject text_completion id=cmpl-ad3ba53d-407c-466b-bd5f-97cb8987af83 at 0x7f6adc12d900> JSON: {\n",
12+
" \"choices\": [\n",
13+
" {\n",
14+
" \"finish_reason\": \"length\",\n",
15+
" \"index\": 0,\n",
16+
" \"logprobs\": null,\n",
17+
" \"text\": \" over the lazy dog.\"\n",
18+
" }\n",
19+
" ],\n",
20+
" \"created\": 1680960690,\n",
21+
" \"id\": \"cmpl-ad3ba53d-407c-466b-bd5f-97cb8987af83\",\n",
22+
" \"model\": \"models/ggml-alpaca.bin\",\n",
23+
" \"object\": \"text_completion\",\n",
24+
" \"usage\": {\n",
25+
" \"completion_tokens\": 5,\n",
26+
" \"prompt_tokens\": 8,\n",
27+
" \"total_tokens\": 13\n",
28+
" }\n",
29+
"}"
30+
]
31+
},
32+
"execution_count": 1,
33+
"metadata": {},
34+
"output_type": "execute_result"
35+
}
36+
],
37+
"source": [
38+
"import openai\n",
39+
"\n",
40+
"openai.api_key = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\" # can be anything\n",
41+
"openai.api_base = \"http://100.64.159.73:8000/v1\"\n",
42+
"\n",
43+
"openai.Completion.create(\n",
44+
" model=\"text-davinci-003\", # currently can be anything\n",
45+
" prompt=\"The quick brown fox jumps\",\n",
46+
" max_tokens=5,\n",
47+
")"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 2,
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"data": {
57+
"text/plain": [
58+
"' over the lazy dog'"
59+
]
60+
},
61+
"execution_count": 2,
62+
"metadata": {},
63+
"output_type": "execute_result"
64+
}
65+
],
66+
"source": [
67+
"import os\n",
68+
"\n",
69+
"os.environ[\"OPENAI_API_KEY\"] = \"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\" # can be anything\n",
70+
"os.environ[\"OPENAI_API_BASE\"] = \"http://100.64.159.73:8000/v1\"\n",
71+
"\n",
72+
"from langchain.llms import OpenAI\n",
73+
"\n",
74+
"llms = OpenAI()\n",
75+
"llms(\n",
76+
" prompt=\"The quick brown fox jumps\",\n",
77+
" stop=[\".\", \"\\n\"],\n",
78+
")"
79+
]
80+
}
81+
],
82+
"metadata": {
83+
"kernelspec": {
84+
"display_name": ".venv",
85+
"language": "python",
86+
"name": "python3"
87+
},
88+
"language_info": {
89+
"codemirror_mode": {
90+
"name": "ipython",
91+
"version": 3
92+
},
93+
"file_extension": ".py",
94+
"mimetype": "text/x-python",
95+
"name": "python",
96+
"nbconvert_exporter": "python",
97+
"pygments_lexer": "ipython3",
98+
"version": "3.8.10"
99+
},
100+
"orig_nbformat": 4
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 2
104+
}

0 commit comments

Comments
 (0)
0