Skip to content

Commit

Permalink
Upgrade Assistant with ollama backend
Browse files Browse the repository at this point in the history
  • Loading branch information
artitw committed Jul 24, 2024
1 parent b460944 commit 2dc8e5c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 99,378 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,16 @@ t2t.Transformer.LANGUAGES
import text2text as t2t
asst = t2t.Assistant()
#OpenAI Chat Completion API
# Streaming example
chat_history = [
{"role": "user", "content": "Hi"},
{"role": "assistant", "content": "Hello, how are you?"},
{"role": "user", "content": "What should I do today?"}
]
num_tokens = asst.chat_completion_tokens(chat_history) #31
print(num_tokens)
result = asst.chat_completion(chat_history, stream=True) #{'role': 'assistant', 'content': '1. Make a list of things to be grateful for.\n2. Go outside and take a walk in nature.\n3. Practice mindfulness meditation.\n4. Connect with a loved one or friend.\n5. Do something kind for someone else.\n6. Engage in a creative activity like drawing or writing.\n7. Read an uplifting book or listen to motivational podcasts.'}
print(result["content"])
for chunk in result:
print(chunk['message']['content'], end='', flush=True)
```

### Tokenization
Expand Down
8 changes: 3 additions & 5 deletions demos/Text2Text_Demos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,16 @@
"\n",
"asst = t2t.Assistant()\n",
"\n",
"#OpenAI Chat Completion API\n",
"\n",
"# Streaming example\n",
"chat_history = [\n",
" {\"role\": \"user\", \"content\": \"Hi\"},\n",
" {\"role\": \"assistant\", \"content\": \"Hello, how are you?\"},\n",
" {\"role\": \"user\", \"content\": \"What should I do today?\"}\n",
"]\n",
"num_tokens = asst.chat_completion_tokens(chat_history) #31\n",
"print(num_tokens)\n",
"\n",
"result = asst.chat_completion(chat_history, stream=True) #{'role': 'assistant', 'content': '1. Make a list of things to be grateful for.\\n2. Go outside and take a walk in nature.\\n3. Practice mindfulness meditation.\\n4. Connect with a loved one or friend.\\n5. Do something kind for someone else.\\n6. Engage in a creative activity like drawing or writing.\\n7. Read an uplifting book or listen to motivational podcasts.'}\n",
"print(result[\"content\"])"
"for chunk in result:\n",
" print(chunk['message']['content'], end='', flush=True)"
],
"metadata": {
"id": "VPMdUSy9YYRl"
Expand Down
Loading

0 comments on commit 2dc8e5c

Please sign in to comment.