初始化项目,由ModelHub XC社区提供模型
Model: ellamind/propella-1-4b Source: Original Platform
This commit is contained in:
26
inference_example.py
Normal file
26
inference_example.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from openai import OpenAI
|
||||
from propella import (
|
||||
create_messages,
|
||||
AnnotationResponse,
|
||||
get_annotation_response_schema,
|
||||
)
|
||||
|
||||
document = "Hi, its me Max."
|
||||
|
||||
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="ellamind/propella-1-4b",
|
||||
messages=create_messages(document),
|
||||
response_format={
|
||||
"type": "json_schema",
|
||||
"json_schema": {
|
||||
"name": "AnnotationResponse",
|
||||
"schema": get_annotation_response_schema(flatten=True, compact_whitespace=True),
|
||||
"strict": True,
|
||||
}
|
||||
},
|
||||
)
|
||||
response_content = response.choices[0].message.content
|
||||
result = AnnotationResponse.model_validate_json(response_content)
|
||||
print(result.model_dump_json(indent=4))
|
||||
Reference in New Issue
Block a user