Skip to content

Commit ebb3ca2

Browse files
committed
added kiara endpoint
1 parent fd7e158 commit ebb3ca2

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "87404224-b84b-409f-8683-c4a243d29722",
6+
"metadata": {},
7+
"source": [
8+
"# Kiara LLM endpoint\n",
9+
"In this notebook we will use yet experimental LLM infrastructure infrastructure. To use it, you must enter two enviroment variables `KIARA_API_KEY` and `KIARA_LLM_SERVER`. Also this method uses the OpenAI API and we just change the `base_url`."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"id": "752e974d-9aaf-44aa-80fb-01a042cf5774",
16+
"metadata": {
17+
"tags": []
18+
},
19+
"outputs": [
20+
{
21+
"data": {
22+
"text/plain": [
23+
"'1.90.0'"
24+
]
25+
},
26+
"execution_count": 1,
27+
"metadata": {},
28+
"output_type": "execute_result"
29+
}
30+
],
31+
"source": [
32+
"import os\n",
33+
"import openai\n",
34+
"openai.__version__"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 2,
40+
"id": "ab55e229-93b9-4e9b-974d-037002690bf0",
41+
"metadata": {
42+
"tags": []
43+
},
44+
"outputs": [],
45+
"source": [
46+
"def prompt_kiara(message:str, model=\"ollama-llama3-3-70b\"):\n",
47+
" \"\"\"A prompt helper function that sends a message to kiara LLM server \n",
48+
" and returns only the text response.\n",
49+
" \"\"\"\n",
50+
" import os\n",
51+
" \n",
52+
" # convert message in the right format if necessary\n",
53+
" if isinstance(message, str):\n",
54+
" message = [{\"role\": \"user\", \"content\": message}]\n",
55+
" \n",
56+
" # setup connection to the LLM\n",
57+
" client = openai.OpenAI(base_url=os.environ.get('KIARA_LLM_SERVER') + \"api/\",\n",
58+
" api_key=os.environ.get('KIARA_API_KEY')\n",
59+
" )\n",
60+
" \n",
61+
" response = client.chat.completions.create(\n",
62+
" model=model,\n",
63+
" messages=message\n",
64+
" )\n",
65+
" \n",
66+
" # extract answer\n",
67+
" return response.choices[0].message.content"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 3,
73+
"id": "a7654a20-a307-4b26-8d25-bef20b70224e",
74+
"metadata": {
75+
"tags": []
76+
},
77+
"outputs": [
78+
{
79+
"data": {
80+
"text/plain": [
81+
"\"It's nice to meet you. Is there something I can help you with or would you like to chat?\""
82+
]
83+
},
84+
"execution_count": 3,
85+
"metadata": {},
86+
"output_type": "execute_result"
87+
}
88+
],
89+
"source": [
90+
"prompt_kiara(\"Hi!\")"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"id": "578e9edd-b58f-4fd0-a56d-1966105221dc",
96+
"metadata": {},
97+
"source": [
98+
"## Exercise\n",
99+
"List the models available in the endpoint and try them out by specifying them when calling `prompt_scadsai_llm()`."
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 4,
105+
"id": "05171ba7-a775-41c5-954d-7d4fc2b5b625",
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"ollama-llama3-3-70b\n",
113+
"vllm-baai-bge-m3\n",
114+
"vllm-deepseek-coder-33b-instruct\n",
115+
"vllm-deepseek-r1-distill-llama-70b\n",
116+
"vllm-llama-3-3-nemotron-super-49b-v1\n",
117+
"vllm-llama-4-scout-17b-16e-instruct\n",
118+
"vllm-meta-llama-llama-3-3-70b-instruct\n",
119+
"vllm-mistral-small-24b-instruct-2501\n",
120+
"vllm-multilingual-e5-large-instruct\n",
121+
"vllm-nvidia-llama-3-3-70b-instruct-fp8\n"
122+
]
123+
}
124+
],
125+
"source": [
126+
"client = openai.OpenAI(base_url=os.environ.get('KIARA_LLM_SERVER') + \"api/\",\n",
127+
" api_key=os.environ.get('KIARA_API_KEY'))\n",
128+
"\n",
129+
"print(\"\\n\".join([model.id for model in client.models.list().data]))"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "7e810ee2-4d22-42f6-add5-532cf95b4b9c",
136+
"metadata": {},
137+
"outputs": [],
138+
"source": []
139+
}
140+
],
141+
"metadata": {
142+
"kernelspec": {
143+
"display_name": "Python 3 (ipykernel)",
144+
"language": "python",
145+
"name": "python3"
146+
},
147+
"language_info": {
148+
"codemirror_mode": {
149+
"name": "ipython",
150+
"version": 3
151+
},
152+
"file_extension": ".py",
153+
"mimetype": "text/x-python",
154+
"name": "python",
155+
"nbconvert_exporter": "python",
156+
"pygments_lexer": "ipython3",
157+
"version": "3.11.11"
158+
}
159+
},
160+
"nbformat": 4,
161+
"nbformat_minor": 5
162+
}

docs/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ parts:
2424
- file: 15_endpoint_apis/01_openai_api.ipynb
2525
- file: 15_endpoint_apis/02_ollama_endpoint.ipynb
2626
- file: 15_endpoint_apis/04_scadsai_llm_endpoint.ipynb
27+
- file: 15_endpoint_apis/09_kiara_llm_endpoint.ipynb
2728
- file: 15_endpoint_apis/06_kisski_endpoint.ipynb
2829
- file: 15_endpoint_apis/03_blablador_endpoint.ipynb
2930
- file: 15_endpoint_apis/05_azure_endpoints.ipynb

0 commit comments

Comments
 (0)