Skip to content

Instantly share code, notes, and snippets.

@jmcdice
Created July 10, 2024 18:03
Show Gist options
  • Save jmcdice/4e36ef159d79fc0ea48a771f6829573a to your computer and use it in GitHub Desktop.
Save jmcdice/4e36ef159d79fc0ea48a771f6829573a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
API_KEY=''
API_BASE='https://genai-proxy.sys.domain.com/v1'
MODEL="vicuna-7b-v1.5"
TEMPERATURE=0
MAX_TOKENS=1024
function chat_with_model() {
local prompt=$1
# Construct the request body
local request_body=$(jq -n \
--arg model "$MODEL" \
--arg prompt "$prompt" \
--argjson temperature $TEMPERATURE \
--argjson max_tokens $MAX_TOKENS \
'{model: $model, prompt: $prompt, temperature: $temperature, max_tokens: $max_tokens}')
# Use the curl command to get the response from the model
local response=$(curl -k ${API_BASE}/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${API_KEY}" \
-d "$request_body")
# Extract and print the response
echo $response | jq -r '.choices[].text'
echo $response | jq -r
}
# Check if a prompt is provided
if [ -z "$1" ]; then
echo "Usage: $0 \"Your prompt here\""
exit 1
fi
# Process the provided prompt
chat_with_model "$1"
example:
$ ./chat_with_model.sh "why is the sky blue?"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 658 100 549 100 109 32 6 0:00:18 0:00:17 0:00:01 145
Unterscheidung von "warum" und "wie"
* Warum: Grund, Ursache, Wurzel
* Wie: Modus, Weise, Art
Der Himmel ist blau, weil es sich um Sonnenlicht handelt. Das ist einfach "wie" es aussieht. Wenn du jedoch fragst, warum es sich um Sonnenlicht handelt, dann fragst du nach dem "warum".
{
"id": "cmpl-ziKFkMwf4sfbEJou8PqCNG",
"object": "text_completion",
"created": 1720634505,
"model": "vicuna-7b-v1.5",
"choices": [
{
"index": 0,
"text": "\nUnterscheidung von \"warum\" und \"wie\"\n\n* Warum: Grund, Ursache, Wurzel\n* Wie: Modus, Weise, Art\n\nDer Himmel ist blau, weil es sich um Sonnenlicht handelt. Das ist einfach \"wie\" es aussieht. Wenn du jedoch fragst, warum es sich um Sonnenlicht handelt, dann fragst du nach dem \"warum\".",
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 7,
"total_tokens": 106,
"completion_tokens": 99
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment