You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-11-25 22:12:29 +02:00
122 lines
3.8 KiB
Plaintext
Vendored
122 lines
3.8 KiB
Plaintext
Vendored
---
|
|
sidebar_position: 1
|
|
description: Get response and other functions to work with OpenAI in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
|
|
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, OpenAI]
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
# Get response
|
|
Generates a response for a given text query
|
|
|
|
|
|
|
|
`Function GetResponse(Val URL, Val Token, Val Model, Val Messages, Val AdditionalParameters = "", Val AdditionalHeaders = "") Export`
|
|
|
|
| Parameter | CLI option | Type | Required | Description |
|
|
|-|-|-|-|-|
|
|
| URL | --url | String | ✔ | OpenAI server URL |
|
|
| Token | --token | String | ✔ | OpenAI authorization token |
|
|
| Model | --model | String | ✔ | Models name |
|
|
| Messages | --msgs | String, Array of String | ✔ | Conversation messages. See GetMessageStructure |
|
|
| AdditionalParameters | --options | Structure Of KeyAndValue | ✖ | Additional request parameters, if necessary |
|
|
| AdditionalHeaders | --headers | Map Of KeyAndValue | ✖ | Additional request headers, if necessary |
|
|
|
|
|
|
Returns: Map Of KeyAndValue - Processing result
|
|
|
|
<br/>
|
|
|
|
:::tip
|
|
Method at API documentation: [Create chat completion](https://platform.openai.com/docs/api-reference/chat/create)
|
|
:::
|
|
<br/>
|
|
|
|
|
|
```bsl title="1C:Enterprise/OneScript code example"
|
|
URL = "https://hut.openintegrations.dev/localai/";
|
|
Token = "12We...";
|
|
|
|
// Text messages
|
|
|
|
Messages = New Array;
|
|
Messages.Add(OPI_OpenAI.GetMessageStructure("user" , "What is 1C:Enterprise?"));
|
|
Messages.Add(OPI_OpenAI.GetMessageStructure("assistant", "1C:Enterprise is a full-stack, low-code platform"));
|
|
Messages.Add(OPI_OpenAI.GetMessageStructure("user" , "When the first version was released?"));
|
|
|
|
Model = "smolvlm-256m-instruct";
|
|
|
|
Result = OPI_OpenAI.GetResponse(URL, Token, Model, Messages);
|
|
|
|
// Pictures
|
|
|
|
Model = "moondream2-20250414";
|
|
File = "https://hut.openintegrations.dev/test_data/picture.jpg"; // URL, Path or Binary Data
|
|
FileName = StrTemplate("%1.png", String(New UUID()));
|
|
Destination = "user_data";
|
|
|
|
Messages = New Array;
|
|
|
|
ImageUpload = OPI_OpenAI.UploadFile(URL, Token, FileName, File, Destination);
|
|
|
|
ImageID = ImageUpload["id"];
|
|
|
|
Description = OPI_OpenAI.GetImageMessageStructure("user", ImageID, "What is in this image?");
|
|
|
|
Messages.Add(Description);
|
|
|
|
Result = OPI_OpenAI.GetResponse(URL, Token, Model, Messages);
|
|
|
|
OPI_OpenAI.DeleteFile(URL, Token, ImageID);
|
|
```
|
|
|
|
|
|
<Tabs>
|
|
|
|
<TabItem value="bash" label="Bash" default>
|
|
```bash
|
|
oint openai GetResponse \
|
|
--url "https://hut.openintegrations.dev/localai/" \
|
|
--token "***" \
|
|
--model "moondream2-20250414" \
|
|
--msgs "[{'role':'user','content':[{'type':'input_image','file_id':'file-10'},{'type':'input_text','text':'What is in this image?'}]}]"
|
|
```
|
|
</TabItem>
|
|
|
|
<TabItem value="bat" label="CMD/Bat" default>
|
|
```batch
|
|
oint openai GetResponse ^
|
|
--url "https://hut.openintegrations.dev/localai/" ^
|
|
--token "***" ^
|
|
--model "moondream2-20250414" ^
|
|
--msgs "[{'role':'user','content':[{'type':'input_image','file_id':'file-10'},{'type':'input_text','text':'What is in this image?'}]}]"
|
|
```
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
|
|
```json title="Result"
|
|
{
|
|
"created": 1757982186,
|
|
"object": "chat.completion",
|
|
"id": "151c60ea-3bf0-4240-86cc-8e03f28f5585",
|
|
"model": "smolvlm-256m-instruct",
|
|
"choices": [
|
|
{
|
|
"index": 0,
|
|
"finish_reason": "stop",
|
|
"message": {
|
|
"role": "assistant",
|
|
"content": "2007"
|
|
}
|
|
}
|
|
],
|
|
"usage": {
|
|
"prompt_tokens": 53,
|
|
"completion_tokens": 5,
|
|
"total_tokens": 58
|
|
}
|
|
}
|
|
```
|