By frank.bailey.jr ·August 21, 2026 · updated August 21, 2026· 2 min read
Task ๐ฎ of KodeKloud's ๐๐ - ๐๐ฒ๐๐ฒ๐น ๐ญ curriculum. Today's task was to Create an AI Chatbot.
devopsmlopsaillmskodekloud

Here were the task requirements: โข Create a client instance using api_key and base_url โข Define a variable prompt with the following content: You are a friendly travel guide. Greet the user and ask where they want to go. โข Send this prompt to the OpenAI chat model and store the result in variable named ๐ณ๐ฆ๐ด๐ฑ๐ฐ๐ฏ๐ด๐ฆ โข Define a variable prompt with the following content: model: openai/gpt-4.1-mini temperature: 0.7 max_tokens: 100
Please review the script example provided. Here are some things to pay attention to:
- I added comments on each section for clarification on what is happening and matching up with the task requirements
- I didn't hard-code ANY api keys or base_urls. This is for 2 reasons, security and to make this modularized. This allows ANYONE to run this script with their own OpenAI credentials
- I used the OpenAI library, not LangChain. This was due to the task requirements
- To set up the local venv environment, I ran the following: ๐๐ข๐๐๐๐๐น -๐ ๐๐๐๐ ๐๐๐๐ && ๐๐๐๐๐๐ ๐๐๐๐/๐๐๐/๐๐๐๐๐๐๐๐ && ๐๐๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐
import os
# declaring the OpenAI client and passing explicitly the api_key and base_url
# the values are passed from the ENV keys found in /root/.bash_profile
client = OpenAI(
base_url=os.environ.get("OPENAI_API_BASE"),
api_key=os.environ.get("OPENAI_API_KEY")
)
prompt="You are a friendly travel guide. Greet the user and ask where they want to go."
# defining greet_user function with a user_prompt parameter for user prompt
def greet_user(user_prompt: str) -> str:
# declaring model, max_tokens, and temperature
response = client.chat.completions.create(
model="openai/gpt-4.1-mini",
messages=[
{
"role": "system",
"content": prompt
},
{
"role": "user",
"content": user_prompt
}
],
temperature=0.7,
max_tokens=100
)
# Extract and return the response text
return response.choices[0].message.content
# declaring main
def main():
response = greet_user("Hello")
if response:
# print the response
print(response)
else:
print("Failed to retrieve response from LLM")
if __name__ == "__main__":
main()
I hope you found this informative! More to come!![task_2_code]