liveBook · Manning

Client library

As explained in Starting Data Analytics with Generative AI and Python

A collection of programming tools, libraries, documentation, and other resources for building applications against a software platform or service.

A client library packages reusable programming tools for connecting an application to a software platform or service. It sits above the API, providing prebuilt functions and classes that reduce repeated integration work. section 1.3.3

For data analytics, a client library can connect Python or another programming language to a generative AI service, allowing code to send requests, receive responses, and embed AI in existing workflows or dashboards. section 1.3.3

Before adopting a client library, check the practical fit:

  • Confirm that the library supports the programming language and service you plan to use. section 1.3.3
  • Review its compatibility and support status rather than assuming that a popular package will remain suitable. section 1.3.3
  • Keep the service credentials, such as an API key or provider token, in the connection setup. section 1.3.3

Calling a model through a Python client

A Python client can be initialized with an API key, configured for a model, and used to submit messages. The returned response can then be printed or incorporated into an analytics workflow. Similar client patterns can target other providers by changing the token and base URL. section 1.3.3

Listing 1.1 Interacting with ChatGPT through the API
from openai import OpenAI
prompt_text = """Generate a list of 20 keywords indicating positive 
sentiment to be used for searching customer reviews in 
Portuguese."""
client = OpenAI(
    api_key=<<your-API-key-here>>,
)
chat_completion = client.chat.completions.create(
    messages=[
    {"role": "system", "content": "You are a scientific assistant, skilled
    at explaining science to schoolchildren."},
    {"role": "user", "content": "Explain resonance to first-graders?"},
    {"role": "assistant", "content": "Alright, kids, today we're going to
    talk about something really cool called resonance! (...)."},
    # Shortened from the full model response
    {"role": "user", "content": "Where can we use it?"}
  ],


    model="gpt-4-0125-preview",
    temperature=0.7,   
)
print(chat_completion.choices[0].message.content)

Inspect a complete Python interaction showing client initialization, conversational messages, model selection, temperature, and response output. section 1.3.3

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Demonstrates client setup, requests, responses, provider selection, and configuration while deferring library internals.
Examples
Shows Python calls to ChatGPT, Llama through a changed base URL, and Vertex AI with model and safety settings.
What it assumes
Assumes a programming environment and provider credentials, while demonstrating API interaction through Python examples.
What you can do after
Build applications that send programmatic requests to generative AI services using a supported client library.
How it connects
Connects APIs, SDKs, Python, JavaScript, LangChain, generative AI, and analytics dashboards.

Also explained in

Compare how 5 books explain client library →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.