Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
ScaDS.AI LLM API Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ScaDS.AI LLM
ScaDS.AI LLM API Examples
Commits
9beafe1c
Commit
9beafe1c
authored
6 months ago
by
Jan Frenzel
Browse files
Options
Downloads
Patches
Plain Diff
Add base example
parent
bcd337e0
No related branches found
No related tags found
1 merge request
!1
Base example
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
base/README.md
+28
-0
28 additions, 0 deletions
base/README.md
base/main.py
+30
-0
30 additions, 0 deletions
base/main.py
base/requirements.txt
+1
-0
1 addition, 0 deletions
base/requirements.txt
with
59 additions
and
0 deletions
base/README.md
0 → 100644
+
28
−
0
View file @
9beafe1c
# Base functionality
This example intends to show you how to:
-
list models
-
select and use the first model with "llama" in its name to display a joke
## Installation
Do the following steps in your bash shell:
```
bash
python3
-m
venv myenv
source
myenv/bin/activate
pip
install
-r
requirements.txt
```
## Usage
1.
Put your API key in the file
`my_key`
.
2.
Then simply start the script
`main.py`
from your bash shell:
```
bash
source
myenv/bin/activate
./main.py
```
3.
Read the joke.
This diff is collapsed.
Click to expand it.
base/main.py
0 → 100755
+
30
−
0
View file @
9beafe1c
#!/usr/bin/env python
# Find instructions how to install dependencies and how to run this script in README.md
from
openai
import
OpenAI
my_api_key
=
""
with
open
(
"
my_key
"
)
as
keyfile
:
my_api_key
=
keyfile
.
readline
()[:
-
1
]
client
=
OpenAI
(
base_url
=
"
https://llm.scads.ai/v1
"
,
api_key
=
my_api_key
)
# Get models
print
(
"""
Available models:
"""
)
for
model
in
client
.
models
.
list
().
data
:
print
(
model
.
id
)
# Find model with "llama" in name
for
model
in
client
.
models
.
list
().
data
:
model_name
=
model
.
id
if
"
llama
"
in
model_name
:
break
# Use model
response
=
client
.
chat
.
completions
.
create
(
messages
=
[{
"
role
"
:
"
user
"
,
"
content
"
:
"
Tell me a joke!
"
}],
model
=
model_name
)
# Print the joke
print
(
"""
Your joke:
"""
)
joke
=
response
.
choices
[
0
].
message
.
content
print
(
joke
)
This diff is collapsed.
Click to expand it.
base/requirements.txt
0 → 100644
+
1
−
0
View file @
9beafe1c
openai
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment