Skip to main content

Completions

The Power of Chat Generation with GenAI

GenAI's advanced chat generation models are masters of language, code, and even images! They understand your input and produce versatile text responses. The key? Crafting effective "prompts" – instructions or examples that guide the model to achieve your desired results.

What can you build with this? The possibilities are endless:

  • Effortless Drafts: Kickstart your writing projects, from emails to reports.
  • Code Generation: Let the AI assist with your coding tasks.
  • Intelligent Q&A: Build systems that answer questions against a vast knowledge base.
  • Text Analysis: Uncover insights buried in documents.
  • Natural Language Interfaces: Make your software more intuitive.
  • Educational Aid: Create engaging tutoring experiences across various subjects.
  • Language Translation: Bridge communication gaps between languages.
  • Game Characters: Bring life to your games with dynamic personalities.

Chat Completions API: The Conversational Tool

Our Chat Completions API excels at both multi-turn conversations and single-query tasks. Here's a simple example:

import os
from mcp import GenAI
from dotenv import load_dotenv

load_dotenv()

## Make Sure you have exported your variable MCP_GENAI_API_KEY

client = GenAI(api_key=os.environ.get("MCP_GENAI_API_KEY"))

response = client.chat.completions.create(
model="mistral",
messages=[
{"role": "system", "content": "You are a medical student with a strong interest in medical history. You have a knack for weaving historical details into compelling narratives."},
{"role": "user", "content": "Write the opening scene of a historical fiction novel where a young medical apprentice, working in a bustling medieval hospital, discovers a hidden scroll containing ancient surgical techniques."}
],
max_tokens=500,
temperature=0.5,
top_p=1.0,
)

print(response.choices[0].message.content)

Understanding the Response

The API provides rich details, including:

  • finish_reason: Indicates why the response ended (e.g., complete, reached a token limit).
  • content: The model-generated message.

Experience the serene possibilities of GenAI's chat generation. Allow your imagination to gently unfold. 💡