Update the "InterleavedTextMedia" type (#635)

## What does this PR do?

This is a long-pending change and particularly important to get done
now.

Specifically:
- we cannot "localize" (aka download) any URLs from media attachments
anywhere near our modeling code. it must be done within llama-stack.
- `PIL.Image` is infesting all our APIs via `ImageMedia ->
InterleavedTextMedia` and that cannot be right at all. Anything in the
API surface must be "naturally serializable". We need a standard `{
type: "image", image_url: "<...>" }` which is more extensible
- `UserMessage`, `SystemMessage`, etc. are moved completely to
llama-stack from the llama-models repository.

See https://github.com/meta-llama/llama-models/pull/244 for the
corresponding PR in llama-models.

## Test Plan

```bash
cd llama_stack/providers/tests

pytest -s -v -k "fireworks or ollama or together" inference/test_vision_inference.py
pytest -s -v -k "(fireworks or ollama or together) and llama_3b" inference/test_text_inference.py
pytest -s -v -k chroma memory/test_memory.py \
  --env EMBEDDING_DIMENSION=384 --env CHROMA_DB_PATH=/tmp/foobar

pytest -s -v -k fireworks agents/test_agents.py  \
   --safety-shield=meta-llama/Llama-Guard-3-8B \
   --inference-model=meta-llama/Llama-3.1-8B-Instruct
```

Updated the client sdk (see PR ...), installed the SDK in the same
environment and then ran the SDK tests:

```bash
cd tests/client-sdk
LLAMA_STACK_CONFIG=together pytest -s -v agents/test_agents.py
LLAMA_STACK_CONFIG=ollama pytest -s -v memory/test_memory.py

# this one needed a bit of hacking in the run.yaml to ensure I could register the vision model correctly
INFERENCE_MODEL=llama3.2-vision:latest LLAMA_STACK_CONFIG=ollama pytest -s -v inference/test_inference.py
```
This commit is contained in:
Ashwin Bharambe 2024-12-17 11:18:31 -08:00 committed by GitHub
parent 10eb31badf
commit 8de8eb03c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 1344 additions and 1801 deletions

File diff suppressed because it is too large Load diff

View file

@ -275,11 +275,9 @@ components:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- $ref: '#/components/schemas/InterleavedContentItem'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
$ref: '#/components/schemas/InterleavedContentItem'
type: array
- $ref: '#/components/schemas/URL'
mime_type:
@ -353,14 +351,7 @@ components:
properties:
content_batch:
items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
type: array
logprobs:
additionalProperties: false
@ -575,14 +566,7 @@ components:
additionalProperties: false
properties:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
role:
const: assistant
default: assistant
@ -603,14 +587,7 @@ components:
additionalProperties: false
properties:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
logprobs:
additionalProperties: false
properties:
@ -788,97 +765,7 @@ components:
properties:
dataset_schema:
additionalProperties:
oneOf:
- additionalProperties: false
properties:
type:
const: string
default: string
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: number
default: number
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: boolean
default: boolean
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: array
default: array
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: object
default: object
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: json
default: json
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: union
default: union
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: chat_completion_input
default: chat_completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: completion_input
default: completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: agent_turn_input
default: agent_turn_input
type: string
required:
- type
type: object
$ref: '#/components/schemas/ParamType'
type: object
identifier:
type: string
@ -951,14 +838,7 @@ components:
properties:
contents:
items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
type: array
model_id:
type: string
@ -1159,22 +1039,20 @@ components:
required:
- status
type: object
ImageMedia:
ImageContentItem:
additionalProperties: false
properties:
image:
oneOf:
- additionalProperties: false
properties:
format:
type: string
format_description:
type: string
title: This class represents an image object. To create
type: object
- $ref: '#/components/schemas/URL'
data:
contentEncoding: base64
type: string
type:
const: image
default: image
type: string
url:
$ref: '#/components/schemas/URL'
required:
- image
- type
type: object
InferenceStep:
additionalProperties: false
@ -1216,6 +1094,17 @@ components:
- bank_id
- documents
type: object
InterleavedContent:
oneOf:
- type: string
- $ref: '#/components/schemas/InterleavedContentItem'
- items:
$ref: '#/components/schemas/InterleavedContentItem'
type: array
InterleavedContentItem:
oneOf:
- $ref: '#/components/schemas/ImageContentItem'
- $ref: '#/components/schemas/TextContentItem'
Job:
additionalProperties: false
properties:
@ -1395,11 +1284,9 @@ components:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- $ref: '#/components/schemas/InterleavedContentItem'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
$ref: '#/components/schemas/InterleavedContentItem'
type: array
- $ref: '#/components/schemas/URL'
document_id:
@ -1428,14 +1315,7 @@ components:
format: date-time
type: string
inserted_context:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
memory_bank_ids:
items:
type: string
@ -1731,6 +1611,98 @@ components:
- rows
- total_count
type: object
ParamType:
oneOf:
- additionalProperties: false
properties:
type:
const: string
default: string
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: number
default: number
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: boolean
default: boolean
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: array
default: array
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: object
default: object
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: json
default: json
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: union
default: union
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: chat_completion_input
default: chat_completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: completion_input
default: completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: agent_turn_input
default: agent_turn_input
type: string
required:
- type
type: object
PhotogenToolDefinition:
additionalProperties: false
properties:
@ -1918,14 +1890,7 @@ components:
- type: object
type: object
query:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
required:
- bank_id
- query
@ -1938,14 +1903,7 @@ components:
additionalProperties: false
properties:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
document_id:
type: string
token_count:
@ -2022,97 +1980,7 @@ components:
type: string
dataset_schema:
additionalProperties:
oneOf:
- additionalProperties: false
properties:
type:
const: string
default: string
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: number
default: number
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: boolean
default: boolean
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: array
default: array
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: object
default: object
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: json
default: json
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: union
default: union
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: chat_completion_input
default: chat_completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: completion_input
default: completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: agent_turn_input
default: agent_turn_input
type: string
required:
- type
type: object
$ref: '#/components/schemas/ParamType'
type: object
metadata:
additionalProperties:
@ -2223,97 +2091,7 @@ components:
provider_scoring_fn_id:
type: string
return_type:
oneOf:
- additionalProperties: false
properties:
type:
const: string
default: string
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: number
default: number
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: boolean
default: boolean
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: array
default: array
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: object
default: object
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: json
default: json
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: union
default: union
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: chat_completion_input
default: chat_completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: completion_input
default: completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: agent_turn_input
default: agent_turn_input
type: string
required:
- type
type: object
$ref: '#/components/schemas/ParamType'
scoring_fn_id:
type: string
required:
@ -2623,97 +2401,7 @@ components:
provider_resource_id:
type: string
return_type:
oneOf:
- additionalProperties: false
properties:
type:
const: string
default: string
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: number
default: number
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: boolean
default: boolean
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: array
default: array
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: object
default: object
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: json
default: json
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: union
default: union
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: chat_completion_input
default: chat_completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: completion_input
default: completion_input
type: string
required:
- type
type: object
- additionalProperties: false
properties:
type:
const: agent_turn_input
default: agent_turn_input
type: string
required:
- type
type: object
$ref: '#/components/schemas/ParamType'
type:
const: scoring_function
default: scoring_function
@ -3112,14 +2800,7 @@ components:
additionalProperties: false
properties:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
role:
const: system
default: system
@ -3128,6 +2809,19 @@ components:
- role
- content
type: object
TextContentItem:
additionalProperties: false
properties:
text:
type: string
type:
const: text
default: text
type: string
required:
- type
- text
type: object
TokenLogProbs:
additionalProperties: false
properties:
@ -3293,14 +2987,7 @@ components:
call_id:
type: string
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
tool_name:
oneOf:
- $ref: '#/components/schemas/BuiltinTool'
@ -3316,14 +3003,7 @@ components:
call_id:
type: string
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
role:
const: ipython
default: ipython
@ -3492,23 +3172,9 @@ components:
additionalProperties: false
properties:
content:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
context:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
- items:
oneOf:
- type: string
- $ref: '#/components/schemas/ImageMedia'
type: array
$ref: '#/components/schemas/InterleavedContent'
role:
const: user
default: user
@ -5297,8 +4963,9 @@ tags:
name: GraphMemoryBankParams
- description: <SchemaDefinition schemaRef="#/components/schemas/HealthInfo" />
name: HealthInfo
- description: <SchemaDefinition schemaRef="#/components/schemas/ImageMedia" />
name: ImageMedia
- description: <SchemaDefinition schemaRef="#/components/schemas/ImageContentItem"
/>
name: ImageContentItem
- name: Inference
- description: <SchemaDefinition schemaRef="#/components/schemas/InferenceStep" />
name: InferenceStep
@ -5306,6 +4973,12 @@ tags:
/>
name: InsertDocumentsRequest
- name: Inspect
- description: <SchemaDefinition schemaRef="#/components/schemas/InterleavedContent"
/>
name: InterleavedContent
- description: <SchemaDefinition schemaRef="#/components/schemas/InterleavedContentItem"
/>
name: InterleavedContentItem
- description: <SchemaDefinition schemaRef="#/components/schemas/Job" />
name: Job
- description: <SchemaDefinition schemaRef="#/components/schemas/JobCancelRequest"
@ -5364,6 +5037,8 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/PaginatedRowsResult"
/>
name: PaginatedRowsResult
- description: <SchemaDefinition schemaRef="#/components/schemas/ParamType" />
name: ParamType
- description: <SchemaDefinition schemaRef="#/components/schemas/PhotogenToolDefinition"
/>
name: PhotogenToolDefinition
@ -5521,6 +5196,9 @@ tags:
- description: <SchemaDefinition schemaRef="#/components/schemas/SystemMessage" />
name: SystemMessage
- name: Telemetry
- description: <SchemaDefinition schemaRef="#/components/schemas/TextContentItem"
/>
name: TextContentItem
- description: <SchemaDefinition schemaRef="#/components/schemas/TokenLogProbs" />
name: TokenLogProbs
- description: <SchemaDefinition schemaRef="#/components/schemas/ToolCall" />
@ -5670,9 +5348,11 @@ x-tagGroups:
- GraphMemoryBank
- GraphMemoryBankParams
- HealthInfo
- ImageMedia
- ImageContentItem
- InferenceStep
- InsertDocumentsRequest
- InterleavedContent
- InterleavedContentItem
- Job
- JobCancelRequest
- JobStatus
@ -5694,6 +5374,7 @@ x-tagGroups:
- OptimizerConfig
- OptimizerType
- PaginatedRowsResult
- ParamType
- PhotogenToolDefinition
- PostTrainingJob
- PostTrainingJobArtifactsResponse
@ -5745,6 +5426,7 @@ x-tagGroups:
- SyntheticDataGenerateRequest
- SyntheticDataGenerationResponse
- SystemMessage
- TextContentItem
- TokenLogProbs
- ToolCall
- ToolCallDelta