diff --git a/README.md b/README.md index 6941e3ef56a3e9fb5f90f458ed99c7577d337d30..d415464ce61211424fc1970aa2318609ea50fe60 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository contains code snippets to get you started with our API. Before y Each example comes with its own installation instructions, because there are examples with several languages and environments which makes this necessary. ## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +A base example is available in directory [base](base). ## Support If you have the feeling that the examples contain errors or otherwise need improvement, please [check whether there is an open issues already](https://gitlab.hrz.tu-chemnitz.de/scads-ai-llm/scads-ai-llm-api-examples/-/issues). If there is no issue yet, create one. @@ -21,4 +21,4 @@ We are very thankful for the examples you provide! We are a small team who canno Show your appreciation to those who have contributed to the project. ## License -Please see the [LICENSE](LICENSE) +Please see the [LICENSE](LICENSE). diff --git a/base/README.md b/base/README.md new file mode 100644 index 0000000000000000000000000000000000000000..90ab9514b1c420c4637b2bd8ef8ecb5881449fcf --- /dev/null +++ b/base/README.md @@ -0,0 +1,28 @@ +# Base functionality + +This is a basic example that 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. Create a file `my_key` and put your API key in the file. For security reasons API Key is necessary. You have to obtain the API Key from the llm.scads.ai team. You can find instructions on https://llm.scads.ai/ . +2. Then simply start the script `main.py` from your bash shell: + +```bash +source myenv/bin/activate +./main.py +``` + +3. Read the joke. diff --git a/base/main.py b/base/main.py new file mode 100755 index 0000000000000000000000000000000000000000..daeb137e2e3dee7508fd96766cb8db3d90aefdb3 --- /dev/null +++ b/base/main.py @@ -0,0 +1,35 @@ +#!/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 = "" +try: + with open("my_key") as keyfile: + my_api_key = keyfile.readline().strip() +except FileNotFoundError: + print("Error: The file 'my_key' was not found. Please make sure the file exists and contains your API key.") + exit(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) diff --git a/base/requirements.txt b/base/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec838c5a8f493ae5a7539652eafae7aab45e0c3f --- /dev/null +++ b/base/requirements.txt @@ -0,0 +1 @@ +openai