Skip to content

< all problems60 · Level 01, LLM APIs

Make Your First Model Call

easy · implement · LLM Fundamentals

Make one request to a model and return everything that comes back, not just the text.

Implement first_call(llm, question, system, max_tokens=100). Make one call with llm.messages.create(...):

  • system goes in the system argument, not in a message.
  • question goes in messages, as a single message whose role is "user".
  • max_tokens is passed through.

The response object has .text, .stop_reason and .usage (with .input_tokens and .output_tokens). Return a dict with four keys:

  • "text": the reply, with surrounding whitespace stripped.
  • "stop_reason": "end_turn" means the model finished; "max_tokens" means it hit your cap and the text is cut off.
  • "input_tokens" and "output_tokens": from .usage.

This runs against a real model, so the tests check properties (the answer is in the text, the call was made once, a tiny cap really does cut the reply off), not exact words.