Skip to content

GitHub Model Chat Basics

The ai chat command allows you to interact w/ GitHub Marketplace models from the command line.

Prerequisites

Before you begin, you'll need to install the ai CLI and set up a GitHub Model.

Install the ai CLI
Setup GitHub Model Marketplace

User and System Prompts

The ai chat command sends a user prompt to GitHub's AI Inference service and displays the response.

User prompts are questions or statements to the model
ai chat --user "What is the capital of France?"
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

user@CHAT: What is the capital of France?

assistant: The capital of France is Paris.
System prompts are special instructions for the model
ai chat --user "What is the capital of France." --system "Always answer in French."
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

user@CHAT: What is the capital of France.

assistant: La capitale de la France est Paris.
--question is an alias for --user
ai chat --question "What is the capital of France?"
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

user@CHAT: What is the capital of France?

assistant: The capital of France is Paris.

User and System prompts from Files

User prompt from a file
ai chat --question "@question.txt"
System prompt from a file
ai chat --question "What is the capital of France?" --system "@system.txt"

Interactive Chat

The --interactive flag allows back-and-forth conversations with the model.

Interactive chat
ai chat --interactive
Interactive with an initial question
ai chat --interactive --question "What is the capital of France?"
Interactive with a system prompt
ai chat --interactive --system "Always answer in French."

Answers and chat history

Output answer to a file
ai chat --question "What is the capital of France?" --output-answer answer.txt
Output chat history to a file
ai chat --interactive --output-chat-history history.jsonl
Input chat history from a file
ai chat --interactive --input-chat-history history.jsonl

Model Selection

Use a different model
ai chat --interactive --model Mistral-large-2407
Set default model
ai config --set chat.model Mistral-large-2407
Use default model
ai chat --interactive

The ai dev new command generates sample code for interacting with the GitHub Model Marketplace.

Prerequisites

Before you begin, you'll need to install the ai CLI and set up a GitHub Model.

Install the ai CLI
Setup GitHub Model Marketplace

List samples

List available templates
ai dev new list
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

Name                                                      Short Name                                       Language                        
------------------------------------------------------    ---------------------------------------------    --------------------------------
Environment Variables                                     .env                                                                             
Azure AI Inference Chat Completions (Streaming)           az-inference-chat-streaming                      C#, Python                      
Helper Function Class Library                             helper-functions                                 C#                              
OpenAI Assistants                                         openai-asst                                      C#, JavaScript, Python          
OpenAI Assistants (Streaming)                             openai-asst-streaming                            C#, JavaScript, Python          
OpenAI Assistants (w/ Code Interpreter)                   openai-asst-streaming-with-code                  C#, JavaScript, Python          
OpenAI Assistants (w/ File Search)                        openai-asst-streaming-with-file-search           C#, JavaScript, Python          
OpenAI Assistants (w/ Functions)                          openai-asst-streaming-with-functions             C#, JavaScript, Python          
OpenAI Assistants Webpage                                 openai-asst-webpage                              JavaScript, TypeScript          
OpenAI Assistants Webpage (w/ Functions)                  openai-asst-webpage-with-functions               JavaScript                      
OpenAI Chat Completions                                   openai-chat                                      C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (Streaming)                       openai-chat-streaming                            C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Data + AI Search)             openai-chat-streaming-with-data                  C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Functions)                    openai-chat-streaming-with-functions             C#, Go, JavaScript, Python      
OpenAI Chat Webpage                                       openai-chat-webpage                              JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Functions)                        openai-chat-webpage-with-functions               JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Speech input/output)              openai-chat-webpage-with-speech                  TypeScript                      
OpenAI Chat Webpage (w/ Functions + Speech)               openai-chat-webpage-with-speech-and-functions    TypeScript                      
Phi-3 Chat Completions (w/ ONNX)                          phi3-onnx-chat-streaming                         C#                              
Phi-3 Chat Completions (w/ ONNX + Functions)              phi3-onnx-chat-streaming-with-functions          C#                              
Semantic Kernel Chat Completions (Streaming)              sk-chat-streaming                                C#                              
Semantic Kernel Chat Completions (w/ Data + AI Search)    sk-chat-streaming-with-data                      C#                              
Semantic Kernel Chat Completions (w/ Functions)           sk-chat-streaming-with-functions                 C#                              
Semantic Kernel Chat Completions (w/ Agents)              sk-chat-with-agents                              C#                              
Speech-to-text                                            speech-to-text                                   C#, Python                      
Speech-to-text (w/ Continuous recognition)                speech-to-text-continuous-reco                   C#, Python                      
Speech-to-text (w/ File input)                            speech-to-text-with-file                         C#, Python                      
Speech-to-text (w/ Keyword detection)                     speech-to-text-with-keyword                      C#, Python                      
Speech-to-text (w/ Translation)                           speech-to-text-with-translation                  C#, Python                      
Text-to-speech                                            text-to-speech                                   C#, Python                      
Text-to-speech (w/ File output)                           text-to-speech-with-file                         C#, Python                      
List only C# samples
ai dev new list --csharp
Filter the list by name
ai dev new list inference --csharp

Generate, build, and run a sample

Generate sample code
ai dev new az-inference-chat-streaming --csharp
cd az-inference-chat-streaming-cs
See the code; learn how it works...

Program.cs
AzureAIInferencingChatCompletionsStreamingClass.cs

Deep dive on how it works

Install dependencies
dotnet restore
Run the sample
ai dev shell
dotnet run

List samples

List available templates
ai dev new list
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

Name                                                      Short Name                                       Language                        
------------------------------------------------------    ---------------------------------------------    --------------------------------
Environment Variables                                     .env                                                                             
Azure AI Inference Chat Completions (Streaming)           az-inference-chat-streaming                      C#, Python                      
Helper Function Class Library                             helper-functions                                 C#                              
OpenAI Assistants                                         openai-asst                                      C#, JavaScript, Python          
OpenAI Assistants (Streaming)                             openai-asst-streaming                            C#, JavaScript, Python          
OpenAI Assistants (w/ Code Interpreter)                   openai-asst-streaming-with-code                  C#, JavaScript, Python          
OpenAI Assistants (w/ File Search)                        openai-asst-streaming-with-file-search           C#, JavaScript, Python          
OpenAI Assistants (w/ Functions)                          openai-asst-streaming-with-functions             C#, JavaScript, Python          
OpenAI Assistants Webpage                                 openai-asst-webpage                              JavaScript, TypeScript          
OpenAI Assistants Webpage (w/ Functions)                  openai-asst-webpage-with-functions               JavaScript                      
OpenAI Chat Completions                                   openai-chat                                      C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (Streaming)                       openai-chat-streaming                            C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Data + AI Search)             openai-chat-streaming-with-data                  C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Functions)                    openai-chat-streaming-with-functions             C#, Go, JavaScript, Python      
OpenAI Chat Webpage                                       openai-chat-webpage                              JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Functions)                        openai-chat-webpage-with-functions               JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Speech input/output)              openai-chat-webpage-with-speech                  TypeScript                      
OpenAI Chat Webpage (w/ Functions + Speech)               openai-chat-webpage-with-speech-and-functions    TypeScript                      
Phi-3 Chat Completions (w/ ONNX)                          phi3-onnx-chat-streaming                         C#                              
Phi-3 Chat Completions (w/ ONNX + Functions)              phi3-onnx-chat-streaming-with-functions          C#                              
Semantic Kernel Chat Completions (Streaming)              sk-chat-streaming                                C#                              
Semantic Kernel Chat Completions (w/ Data + AI Search)    sk-chat-streaming-with-data                      C#                              
Semantic Kernel Chat Completions (w/ Functions)           sk-chat-streaming-with-functions                 C#                              
Semantic Kernel Chat Completions (w/ Agents)              sk-chat-with-agents                              C#                              
Speech-to-text                                            speech-to-text                                   C#, Python                      
Speech-to-text (w/ Continuous recognition)                speech-to-text-continuous-reco                   C#, Python                      
Speech-to-text (w/ File input)                            speech-to-text-with-file                         C#, Python                      
Speech-to-text (w/ Keyword detection)                     speech-to-text-with-keyword                      C#, Python                      
Speech-to-text (w/ Translation)                           speech-to-text-with-translation                  C#, Python                      
Text-to-speech                                            text-to-speech                                   C#, Python                      
Text-to-speech (w/ File output)                           text-to-speech-with-file                         C#, Python                      
List only Go samples
ai dev new list --go
Filter the list by name
ai dev new list inference --go

Generate, build, and run a sample

... 🚧 UNDER CONSTRUCTION ...

List samples

List available templates
ai dev new list
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

Name                                                      Short Name                                       Language                        
------------------------------------------------------    ---------------------------------------------    --------------------------------
Environment Variables                                     .env                                                                             
Azure AI Inference Chat Completions (Streaming)           az-inference-chat-streaming                      C#, Python                      
Helper Function Class Library                             helper-functions                                 C#                              
OpenAI Assistants                                         openai-asst                                      C#, JavaScript, Python          
OpenAI Assistants (Streaming)                             openai-asst-streaming                            C#, JavaScript, Python          
OpenAI Assistants (w/ Code Interpreter)                   openai-asst-streaming-with-code                  C#, JavaScript, Python          
OpenAI Assistants (w/ File Search)                        openai-asst-streaming-with-file-search           C#, JavaScript, Python          
OpenAI Assistants (w/ Functions)                          openai-asst-streaming-with-functions             C#, JavaScript, Python          
OpenAI Assistants Webpage                                 openai-asst-webpage                              JavaScript, TypeScript          
OpenAI Assistants Webpage (w/ Functions)                  openai-asst-webpage-with-functions               JavaScript                      
OpenAI Chat Completions                                   openai-chat                                      C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (Streaming)                       openai-chat-streaming                            C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Data + AI Search)             openai-chat-streaming-with-data                  C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Functions)                    openai-chat-streaming-with-functions             C#, Go, JavaScript, Python      
OpenAI Chat Webpage                                       openai-chat-webpage                              JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Functions)                        openai-chat-webpage-with-functions               JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Speech input/output)              openai-chat-webpage-with-speech                  TypeScript                      
OpenAI Chat Webpage (w/ Functions + Speech)               openai-chat-webpage-with-speech-and-functions    TypeScript                      
Phi-3 Chat Completions (w/ ONNX)                          phi3-onnx-chat-streaming                         C#                              
Phi-3 Chat Completions (w/ ONNX + Functions)              phi3-onnx-chat-streaming-with-functions          C#                              
Semantic Kernel Chat Completions (Streaming)              sk-chat-streaming                                C#                              
Semantic Kernel Chat Completions (w/ Data + AI Search)    sk-chat-streaming-with-data                      C#                              
Semantic Kernel Chat Completions (w/ Functions)           sk-chat-streaming-with-functions                 C#                              
Semantic Kernel Chat Completions (w/ Agents)              sk-chat-with-agents                              C#                              
Speech-to-text                                            speech-to-text                                   C#, Python                      
Speech-to-text (w/ Continuous recognition)                speech-to-text-continuous-reco                   C#, Python                      
Speech-to-text (w/ File input)                            speech-to-text-with-file                         C#, Python                      
Speech-to-text (w/ Keyword detection)                     speech-to-text-with-keyword                      C#, Python                      
Speech-to-text (w/ Translation)                           speech-to-text-with-translation                  C#, Python                      
Text-to-speech                                            text-to-speech                                   C#, Python                      
Text-to-speech (w/ File output)                           text-to-speech-with-file                         C#, Python                      
List only Java samples
ai dev new list --java
Filter the list by name
ai dev new list inference --java

Generate, build, and run a sample

... 🚧 UNDER CONSTRUCTION ...

List samples

List available templates
ai dev new list
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

Name                                                      Short Name                                       Language                        
------------------------------------------------------    ---------------------------------------------    --------------------------------
Environment Variables                                     .env                                                                             
Azure AI Inference Chat Completions (Streaming)           az-inference-chat-streaming                      C#, Python                      
Helper Function Class Library                             helper-functions                                 C#                              
OpenAI Assistants                                         openai-asst                                      C#, JavaScript, Python          
OpenAI Assistants (Streaming)                             openai-asst-streaming                            C#, JavaScript, Python          
OpenAI Assistants (w/ Code Interpreter)                   openai-asst-streaming-with-code                  C#, JavaScript, Python          
OpenAI Assistants (w/ File Search)                        openai-asst-streaming-with-file-search           C#, JavaScript, Python          
OpenAI Assistants (w/ Functions)                          openai-asst-streaming-with-functions             C#, JavaScript, Python          
OpenAI Assistants Webpage                                 openai-asst-webpage                              JavaScript, TypeScript          
OpenAI Assistants Webpage (w/ Functions)                  openai-asst-webpage-with-functions               JavaScript                      
OpenAI Chat Completions                                   openai-chat                                      C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (Streaming)                       openai-chat-streaming                            C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Data + AI Search)             openai-chat-streaming-with-data                  C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Functions)                    openai-chat-streaming-with-functions             C#, Go, JavaScript, Python      
OpenAI Chat Webpage                                       openai-chat-webpage                              JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Functions)                        openai-chat-webpage-with-functions               JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Speech input/output)              openai-chat-webpage-with-speech                  TypeScript                      
OpenAI Chat Webpage (w/ Functions + Speech)               openai-chat-webpage-with-speech-and-functions    TypeScript                      
Phi-3 Chat Completions (w/ ONNX)                          phi3-onnx-chat-streaming                         C#                              
Phi-3 Chat Completions (w/ ONNX + Functions)              phi3-onnx-chat-streaming-with-functions          C#                              
Semantic Kernel Chat Completions (Streaming)              sk-chat-streaming                                C#                              
Semantic Kernel Chat Completions (w/ Data + AI Search)    sk-chat-streaming-with-data                      C#                              
Semantic Kernel Chat Completions (w/ Functions)           sk-chat-streaming-with-functions                 C#                              
Semantic Kernel Chat Completions (w/ Agents)              sk-chat-with-agents                              C#                              
Speech-to-text                                            speech-to-text                                   C#, Python                      
Speech-to-text (w/ Continuous recognition)                speech-to-text-continuous-reco                   C#, Python                      
Speech-to-text (w/ File input)                            speech-to-text-with-file                         C#, Python                      
Speech-to-text (w/ Keyword detection)                     speech-to-text-with-keyword                      C#, Python                      
Speech-to-text (w/ Translation)                           speech-to-text-with-translation                  C#, Python                      
Text-to-speech                                            text-to-speech                                   C#, Python                      
Text-to-speech (w/ File output)                           text-to-speech-with-file                         C#, Python                      
List only JavaScript samples
ai dev new list --javascript
Filter the list by name
ai dev new list inference --javascript

Generate, build, and run a sample

... 🚧 UNDER CONSTRUCTION ...

List samples

List available templates
ai dev new list
AI - Azure AI CLI, Version 1.0.0
Copyright (c) 2024 Microsoft Corporation. All Rights Reserved.

Name                                                      Short Name                                       Language                        
------------------------------------------------------    ---------------------------------------------    --------------------------------
Environment Variables                                     .env                                                                             
Azure AI Inference Chat Completions (Streaming)           az-inference-chat-streaming                      C#, Python                      
Helper Function Class Library                             helper-functions                                 C#                              
OpenAI Assistants                                         openai-asst                                      C#, JavaScript, Python          
OpenAI Assistants (Streaming)                             openai-asst-streaming                            C#, JavaScript, Python          
OpenAI Assistants (w/ Code Interpreter)                   openai-asst-streaming-with-code                  C#, JavaScript, Python          
OpenAI Assistants (w/ File Search)                        openai-asst-streaming-with-file-search           C#, JavaScript, Python          
OpenAI Assistants (w/ Functions)                          openai-asst-streaming-with-functions             C#, JavaScript, Python          
OpenAI Assistants Webpage                                 openai-asst-webpage                              JavaScript, TypeScript          
OpenAI Assistants Webpage (w/ Functions)                  openai-asst-webpage-with-functions               JavaScript                      
OpenAI Chat Completions                                   openai-chat                                      C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (Streaming)                       openai-chat-streaming                            C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Data + AI Search)             openai-chat-streaming-with-data                  C#, Go, Java, JavaScript, Python
OpenAI Chat Completions (w/ Functions)                    openai-chat-streaming-with-functions             C#, Go, JavaScript, Python      
OpenAI Chat Webpage                                       openai-chat-webpage                              JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Functions)                        openai-chat-webpage-with-functions               JavaScript, TypeScript          
OpenAI Chat Webpage (w/ Speech input/output)              openai-chat-webpage-with-speech                  TypeScript                      
OpenAI Chat Webpage (w/ Functions + Speech)               openai-chat-webpage-with-speech-and-functions    TypeScript                      
Phi-3 Chat Completions (w/ ONNX)                          phi3-onnx-chat-streaming                         C#                              
Phi-3 Chat Completions (w/ ONNX + Functions)              phi3-onnx-chat-streaming-with-functions          C#                              
Semantic Kernel Chat Completions (Streaming)              sk-chat-streaming                                C#                              
Semantic Kernel Chat Completions (w/ Data + AI Search)    sk-chat-streaming-with-data                      C#                              
Semantic Kernel Chat Completions (w/ Functions)           sk-chat-streaming-with-functions                 C#                              
Semantic Kernel Chat Completions (w/ Agents)              sk-chat-with-agents                              C#                              
Speech-to-text                                            speech-to-text                                   C#, Python                      
Speech-to-text (w/ Continuous recognition)                speech-to-text-continuous-reco                   C#, Python                      
Speech-to-text (w/ File input)                            speech-to-text-with-file                         C#, Python                      
Speech-to-text (w/ Keyword detection)                     speech-to-text-with-keyword                      C#, Python                      
Speech-to-text (w/ Translation)                           speech-to-text-with-translation                  C#, Python                      
Text-to-speech                                            text-to-speech                                   C#, Python                      
Text-to-speech (w/ File output)                           text-to-speech-with-file                         C#, Python                      
List only Python samples
ai dev new list --python
Filter the list by name
ai dev new list inference --python

Generate, build, and run a sample

Generate sample code
ai dev new az-inference-chat-streaming --python
cd az-inference-chat-streaming-py
See the code; learn what it does...

main.py
requirements.txt

Deep dive on how it works

Create virtual environment
python -m venv env
env/Scripts/activate
Install requirements
pip install -r requirements.txt
Run the sample
ai dev shell
python main.py
Create virtual environment
python3 -m venv env
source env/bin/activate
Install requirements
pip install -r requirements.txt
Run the sample
ai dev shell
python3 main.py
Create virtual environment
python3 -m venv env
source env/bin/activate
Install requirements
pip install -r requirements.txt
Run the sample
ai dev shell
python3 main.py