Skip to content

Commit

Permalink
Update for gpt-4o
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKoleczek committed May 14, 2024
1 parent c960c71 commit 315c002
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 193 deletions.
18 changes: 9 additions & 9 deletions notebooks/llm/gpt-4-v.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"source": [
"## Creating Prompts\n",
"\n",
"Prompts for GPT-4V follow the familiar [chat completion](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) format as the non-vision enabled models like `gpt-35-turbo` and `gpt-4-turbo`.\n",
"Prompts for GPT-4V follow the familiar [chat completion](https://platform.openai.com/docs/guides/text-generation/chat-completions-api) format as the non-vision enabled models like `gpt-35-turbo`, `gpt-4-turbo`, and `gpt-4o`.\n",
"\n",
"A chat completion prompt for one of those models looks as follows:\n",
"\n",
Expand Down Expand Up @@ -164,7 +164,7 @@
{
"data": {
"text/plain": [
"ChatCompletion(id='chatcmpl-9MOpZiTg5uUclrUH9EbvY9xGVcCm0', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Semantic Kernel works by integrating multiple plugins and APIs to recall memory, create plans, and perform custom tasks while maintaining context, ultimately providing a tailored output based on specific AI services and monitored interactions.', role='assistant', function_call=None, tool_calls=None))], created=1715125693, model='gpt-4-turbo-2024-04-09', object='chat.completion', system_fingerprint='fp_5d12056990', usage=CompletionUsage(completion_tokens=38, prompt_tokens=1565, total_tokens=1603))"
"ChatCompletion(id='chatcmpl-9OZmHouaxThFvhTb6A3MDES2ccjGE', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Semantic Kernel processes tasks by integrating various plugins and APIs within a contextual framework to generate and return structured results based on user prompts.', role='assistant', function_call=None, tool_calls=None))], created=1715644429, model='gpt-4o-2024-05-13', object='chat.completion', system_fingerprint='fp_927397958d', usage=CompletionUsage(completion_tokens=25, prompt_tokens=1565, total_tokens=1590))"
]
},
"execution_count": 2,
Expand All @@ -180,7 +180,7 @@
"prompt = chat_prompt(messages, variables={\"persona\": \"assistant\", \"library\": \"Semantic Kernel\"})\n",
"\n",
"response = client.chat.completions.create(\n",
" model=\"gpt-4-turbo-2024-04-09\",\n",
" model=\"gpt-4o-2024-05-13\",\n",
" messages=prompt,\n",
" max_tokens=200,\n",
")\n",
Expand All @@ -207,12 +207,12 @@
"data": {
"text/plain": [
"{'choices': [{'finish_reason': 'stop',\n",
" 'message': 'The Semantic Kernel functions by selecting and invoking AI services based on a model, rendering prompts, and parsing responses, while managing reliability and telemetry through a centralized kernel that integrates with applications via event notifications and result creation.'},\n",
" 'message': 'Semantic Kernel processes tasks by invoking various AI services and plugins to recall memory, create plans, access APIs, and execute functions, ultimately returning summarized results to the user.'},\n",
" {'finish_reason': 'stop',\n",
" 'message': \"The Semantic Kernel functions by selecting and invoking AI services based on rendered prompts, managing responses through parsing and templating, and integrating reliability, telemetry, and monitoring within the kernel's architecture to ensure responsible AI usage.\"}],\n",
" 'completion_tokens': 84,\n",
" 'message': 'Semantic Kernel processes user prompts by leveraging a series of plugins and AI services to generate and execute tasks, ultimately returning the results to the user.'}],\n",
" 'completion_tokens': 61,\n",
" 'prompt_tokens': 1565,\n",
" 'system_fingerprint': 'fp_5d12056990'}"
" 'system_fingerprint': 'fp_927397958d'}"
]
},
"execution_count": 3,
Expand All @@ -227,7 +227,7 @@
"client = openai_client()\n",
"\n",
"response = chat_completion(\n",
" messages=prompt, model=\"gpt-4-turbo-2024-04-09\", client=client, max_tokens=200, temperature=0.5, seed=42, n=2\n",
" messages=prompt, model=\"gpt-4o-2024-05-13\", client=client, max_tokens=200, temperature=0.5, seed=42, n=2\n",
")\n",
"response"
]
Expand All @@ -241,7 +241,7 @@
"data": {
"text/plain": [
"{'finish_reason': 'stop',\n",
" 'message': 'The Semantic Kernel functions by selecting and invoking AI services based on a model, rendering prompts, and parsing responses, while managing reliability and telemetry through a centralized kernel that integrates with applications via event notifications and result creation.'}"
" 'message': 'Semantic Kernel processes tasks by invoking various AI services and plugins to recall memory, create plans, access APIs, and execute functions, ultimately returning summarized results to the user.'}"
]
},
"execution_count": 4,
Expand Down
8 changes: 4 additions & 4 deletions notebooks/llm/ollama_intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
{
"data": {
"text/plain": [
"{'message': 'Hello there! How can I assist you today?\\n',\n",
"{'message': 'Hi there! How can I assist you today?\\n',\n",
" 'completion_tokens': 12,\n",
" 'response_duration': 2.48722}"
" 'response_duration': 2.92105}"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -150,7 +150,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[{'name': 'llama3:8b', 'model': 'llama3:8b', 'modified_at': '2024-05-07T12:50:01.227242442Z', 'size': 4661224578, 'size_readable': '4.34 GB', 'details': {'parent_model': '', 'format': 'gguf', 'family': 'llama', 'families': ['llama'], 'parameter_size': '8B', 'quantization_level': 'Q4_0'}}, {'name': 'phi3:latest', 'model': 'phi3:latest', 'modified_at': '2024-05-05T18:06:59.995187156Z', 'size': 2318920898, 'size_readable': '2.16 GB', 'details': {'parent_model': '', 'format': 'gguf', 'family': 'llama', 'families': ['llama'], 'parameter_size': '4B', 'quantization_level': 'Q4_K_M'}}]\n"
"[{'name': 'llama3:8b', 'model': 'llama3:8b', 'modified_at': '2024-05-07T12:50:01.227242442Z', 'size': 4661224578, 'size_readable': '4.34 GB', 'details': {'parent_model': '', 'format': 'gguf', 'family': 'llama', 'families': ['llama'], 'parameter_size': '8B', 'quantization_level': 'Q4_0'}}, {'name': 'phi3:latest', 'model': 'phi3:latest', 'modified_at': '2024-05-07T23:47:58.436751717Z', 'size': 2318920898, 'size_readable': '2.16 GB', 'details': {'parent_model': '', 'format': 'gguf', 'family': 'llama', 'families': ['llama'], 'parameter_size': '4B', 'quantization_level': 'Q4_K_M'}}]\n"
]
}
],
Expand Down Expand Up @@ -192,7 +192,7 @@
"data": {
"text/plain": [
"{'modelfile': '# Modelfile generated by \"ollama show\"\\n# To build a new Modelfile based on this one, replace the FROM line with:\\n# FROM phi3:latest\\n\\nFROM /usr/share/ollama/.ollama/models/blobs/sha256-4fed7364ee3e0c7cb4fe0880148bfdfcd1b630981efa0802a6b62ee52e7da97e\\nTEMPLATE \"\"\"{{ if .System }}<|system|>\\n{{ .System }}<|end|>\\n{{ end }}{{ if .Prompt }}<|user|>\\n{{ .Prompt }}<|end|>\\n{{ end }}<|assistant|>\\n{{ .Response }}<|end|>\\n\"\"\"\\nPARAMETER num_keep 4\\nPARAMETER stop \"<|user|>\"\\nPARAMETER stop \"<|assistant|>\"\\nPARAMETER stop \"<|system|>\"\\nPARAMETER stop \"<|end|>\"\\nPARAMETER stop \"<|endoftext|>\"',\n",
" 'parameters': 'stop \"<|user|>\"\\nstop \"<|assistant|>\"\\nstop \"<|system|>\"\\nstop \"<|end|>\"\\nstop \"<|endoftext|>\"\\nnum_keep 4',\n",
" 'parameters': 'num_keep 4\\nstop \"<|user|>\"\\nstop \"<|assistant|>\"\\nstop \"<|system|>\"\\nstop \"<|end|>\"\\nstop \"<|endoftext|>\"',\n",
" 'template': '{{ if .System }}<|system|>\\n{{ .System }}<|end|>\\n{{ end }}{{ if .Prompt }}<|user|>\\n{{ .Prompt }}<|end|>\\n{{ end }}<|assistant|>\\n{{ .Response }}<|end|>\\n',\n",
" 'details': {'parent_model': '',\n",
" 'format': 'gguf',\n",
Expand Down
11 changes: 6 additions & 5 deletions notebooks/llm/openai_chat_completion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"source": [
"from not_again_ai.llm.openai_api.tokens import num_tokens_from_messages\n",
"\n",
"num_tokens = num_tokens_from_messages(messages=messages, model=\"gpt-3.5-turbo\")\n",
"num_tokens = num_tokens_from_messages(messages=messages, model=\"gpt-4o-2024-05-13\")\n",
"print(num_tokens)"
]
},
Expand All @@ -174,13 +174,14 @@
"{'choices': [{'finish_reason': 'stop',\n",
" 'message': None,\n",
" 'tool_names': ['get_current_weather'],\n",
" 'tool_args_list': [{'location': 'Boston, MA', 'format': 'celsius'}]},\n",
" 'tool_args_list': [{'location': 'Boston, MA', 'format': 'fahrenheit'}]},\n",
" {'finish_reason': 'stop',\n",
" 'message': None,\n",
" 'tool_names': ['get_current_weather'],\n",
" 'tool_args_list': [{'location': 'Boston, MA', 'format': 'celsius'}]}],\n",
" 'tool_args_list': [{'location': 'Boston, MA', 'format': 'fahrenheit'}]}],\n",
" 'completion_tokens': 40,\n",
" 'prompt_tokens': 105}"
" 'prompt_tokens': 101,\n",
" 'system_fingerprint': 'fp_729ea513f7'}"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -228,7 +229,7 @@
"\n",
"response = chat_completion(\n",
" messages=messages,\n",
" model=\"gpt-3.5-turbo-0125\",\n",
" model=\"gpt-4o-2024-05-13\",\n",
" client=client,\n",
" tools=tools,\n",
" tool_choice=\"required\", # Force the model to use the tool\n",
Expand Down
Loading

0 comments on commit 315c002

Please sign in to comment.