Skip to content

Commit 3af1d7d

Browse files
Merge pull request #294 from jeremiaswerner/initial_ai_samples
Provide basic AI examples
2 parents a814e77 + 3625bde commit 3af1d7d

47 files changed

Lines changed: 5197 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ai/common.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
3+
# ==============================
4+
# COMMON FUNCTIONS
5+
# ==============================
6+
7+
RED="\033[31m"
8+
BLUE="\033[94m"
9+
GREEN="\033[32m"
10+
ENDCOLOR="\033[0m"
11+
12+
function print_error {
13+
echo -e "${RED}\n==========================================${ENDCOLOR}"
14+
echo -e "${RED} FAILED${ENDCOLOR}"
15+
echo -e "${RED}==========================================\n${ENDCOLOR}"
16+
echo -e "${RED}$1${ENDCOLOR}"
17+
echo -e ""
18+
}
19+
function print_msg {
20+
echo -e "${BLUE}$1${ENDCOLOR}"
21+
}
22+
function print_success {
23+
echo -e "${GREEN}$1${ENDCOLOR}"
24+
}
25+
26+
# Helper function to check whether prerequisites are installed
27+
function check_prerequisites {
28+
# Ensure that jq tool is installed
29+
if ! command -v jq &>/dev/null; then
30+
print_error "'jq' tool is not installed"
31+
exit 1
32+
fi
33+
}
34+
35+
# ==============================
36+
# COMMON IBMCLOUD HELPERS
37+
# ==============================
38+
39+
# helper function to check whether IBM Cloud CLI plugins should get updated, or not
40+
function ensure_plugin_is_up_to_date() {
41+
echo "Checking $1 ..."
42+
# check whether plugin is installed
43+
if ! ibmcloud plugin show $1 -q >/dev/null; then
44+
# install it
45+
ibmcloud plugin install $1 -f --quiet
46+
else
47+
# check whether there is an update available
48+
ibmcloud plugin update $1 -f --quiet
49+
fi
50+
}
51+
52+
function target_region {
53+
print_msg "\nTargetting IBM Cloud region '$1' ..."
54+
current_region=$(ibmcloud target --output JSON |jq -r '.region|.name')
55+
if [[ "$current_region" != "$1" ]]; then
56+
ibmcloud target -r $1 --quiet
57+
fi
58+
}
59+
60+
function target_resource_group {
61+
print_msg "\nTargetting resource group '$1' ..."
62+
current_resource_group_guid=$(ibmcloud target --output JSON |jq -r '.resource_group|.guid')
63+
new_resource_group_guid=$(ibmcloud resource group $1 -output json|jq -r '.[0].id')
64+
if [[ "$current_resource_group_guid" != "$new_resource_group_guid" ]]; then
65+
ibmcloud target -g $1 --quiet
66+
fi
67+
echo "Done"
68+
}
69+
70+
function does_instance_exist {
71+
(( $(ibmcloud resource search "service_name:\"$1\" AND name:\"$2\"" --output JSON|jq -r '.items|length') > 0 ))
72+
}
73+
74+
function does_serviceid_exist {
75+
(( $(ibmcloud resource search "type:serviceid AND name:\"$1\"" --output JSON|jq -r '.items|length') > 0 ))
76+
}
77+
78+
function has_bucket_name_with_prefix {
79+
buckets=$(ibmcloud cos buckets -output json)
80+
COS_BUCKET_NAME=""
81+
if [[ "$(echo "${buckets}" | jq -r '.Buckets')" != "null" ]]; then
82+
for bucket in $(echo "${buckets}" | jq -r '.Buckets|.[] | @base64'); do
83+
_jq() {
84+
echo ${bucket} | base64 --decode | jq -r ${1}
85+
}
86+
bucket_name=$(_jq '.Name')
87+
if [[ "$bucket_name" =~ ^$1-* ]]; then
88+
COS_BUCKET_NAME=$bucket_name
89+
fi
90+
done
91+
fi
92+
echo $COS_BUCKET_NAME
93+
}
94+
95+
96+
function abortScript() {
97+
if [[ "${CLEANUP_ON_ERROR}" == true ]]; then
98+
clean
99+
else
100+
print_msg "\nSkipping deletion of the created IBM Cloud resources. Please be aware that the created resources will occur costs in your account."
101+
echo "$ ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION"
102+
ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION
103+
fi
104+
exit 1
105+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# LLM Configuration (OpenAI-compatible API)
2+
# Configure your inference backend here
3+
4+
# IBM watsonx.ai
5+
INFERENCE_BASE_URL=https://eu-de.ml.cloud.ibm.com
6+
INFERENCE_API_KEY="YOUR_API_KEY"
7+
INFERENCE_MODEL_NAME="meta-llama/llama-3-2-11b-vision-instruct"
8+
INFERENCE_PROJECT_ID="YOUR_PROJECT_ID"
9+
10+
11+
# IBM Cloud Configuration (for deployment)
12+
REGION=eu-de
13+
PROJECT_NAME=langchain-skills-agent-project
14+
NAME_PREFIX=ce-langchain-agent
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Environment files
2+
.env
3+
4+
# Python
5+
__pycache__/
6+
*.py[oc]
7+
.venv/
8+
*.egg-info
9+
10+
# IDE
11+
.vscode/
12+
.idea/
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db

0 commit comments

Comments
 (0)