### Get Available Models (Python) Source: https://vsegpt.ru/Docs/API/Code Example of fetching a list of all available models supported by the Vsegpt API. This helps in choosing the right model for your task. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") models = client.models.list() for model in models.data: print(model.id) ``` -------------------------------- ### Third-Party Libraries and Examples (C# async) Source: https://vsegpt.ru/Docs/API/Code An asynchronous example in C# for interacting with Vsegpt, suitable for .NET applications. Demonstrates non-blocking API calls. ```csharp using System; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; public class VsegptClient { private readonly HttpClient _httpClient; private readonly string _apiKey; public VsegptClient(string apiKey) { _httpClient = new HttpClient(); _apiKey = apiKey; _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiKey); } public async Task GetChatCompletionAsync(string prompt) { var requestData = new { model = "gpt-4o-mini", messages = new[] { new { role = "system", content = "You are a helpful assistant." }, new { role = "user", content = prompt } } }; var jsonContent = JsonSerializer.Serialize(requestData); var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("https://api.vsegpt.ai/v1/chat/completions", httpContent); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var responseObject = JsonSerializer.Deserialize(responseString); return responseObject.choices[0].message.content; } public static async Task Main(string[] args) { var client = new VsegptClient("YOUR_API_KEY"); var completion = await client.GetChatCompletionAsync("Hello!"); Console.WriteLine(completion); } } ``` -------------------------------- ### Third-Party Libraries and Examples (NodeJS) Source: https://vsegpt.ru/Docs/API/Code Provides a NodeJS example for interacting with third-party libraries or services that might integrate with Vsegpt. Useful for web development. ```javascript const axios = require('axios'); const apiKey = 'YOUR_API_KEY'; const apiUrl = 'https://api.vsegpt.ai/v1/chat/completions'; axios.post(apiUrl, { model: 'gpt-4o-mini', messages: [ {role: 'system', content: 'You are a helpful assistant.'}, {role: 'user', content: 'Hello!'} ] }, { headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data.choices[0].message.content); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Basic Example - gpt-4o-mini Call (Google Colab) Source: https://vsegpt.ru/Docs/API/Code A basic example in Google Colab demonstrating how to call the gpt-4o-mini model. This is a starting point for users of the platform. ```python # Install the Vsegpt library !pip install vsegpt from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ] ) print(response.choices[0].message.content) ``` -------------------------------- ### Get Account Balance (Python) Source: https://vsegpt.ru/Docs/API/Code Example of retrieving your current account balance using the Vsegpt API in Python. This is essential for monitoring usage and costs. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") balance = client.billing.get_balance() print(f"Your current balance is: {balance.amount}") ``` -------------------------------- ### Third-Party Libraries and Examples (TypeScript with OpenAI library) Source: https://vsegpt.ru/Docs/API/Code Example using the official OpenAI library in TypeScript to interact with Vsegpt. This leverages existing SDKs for convenience. ```typescript import OpenAI from 'openai'; const openai = new OpenAI({ apiKey: 'YOUR_API_KEY', baseURL: 'https://api.vsegpt.ai/v1', }); async function main() { const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ] }); console.log(completion.choices[0].message.content); } main(); ``` -------------------------------- ### Basic API Call (Python) Source: https://vsegpt.ru/Docs/API/Code A fundamental example demonstrating how to make a basic API call using Python. This snippet is useful for getting started with text generation. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ] ) print(response.choices[0].message.content) ``` -------------------------------- ### FLUX.2 Pro Image Generation Examples Source: https://vsegpt.ru/Docs/Models/Txt2Img Examples demonstrating text-to-image generation with FLUX.2 Pro, including HEX color usage and image referencing. ```string "a wall painted in color #2ECC71" ``` ```string "gradient from hex #FF6B6B to hex #4ECDC4" ``` ```string "the car in color #1A1A1A with accents in #FFD700" ``` ```string "@image1 wearing the outfit from @image2" ``` ```string "combine the style of @image1 with the composition of @image2" ``` ```string "the person from @image1 in the setting from @image3" ``` -------------------------------- ### Get Reasoning in Reasoning Models (Python) Source: https://vsegpt.ru/Docs/API/Code Example of retrieving reasoning outputs from models like o1 and R1 using the Vsegpt API. This is useful for understanding the model's thought process. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") response = client.chat.completions.create( model="o1", # or "R1" messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Solve this math problem: 2 + 2"} ], reasoning=True ) print(response.choices[0].message.content) ``` -------------------------------- ### Flux 2 [klein] 4B Advanced Prompting Examples Source: https://vsegpt.ru/Docs/Models/Txt2Img Examples demonstrating advanced prompting techniques for the Flux 2 [klein] 4B model, including HEX color control, image referencing with '@', and structured JSON prompts for detailed scene control. ```text "a wall painted in color #2ECC71" "gradient from hex #FF6B6B to hex #4ECDC4" "the car in color #1A1A1A with accents in #FFD700" ``` ```text "@image1 wearing the outfit from @image2" "combine the style of @image1 with the composition of @image2" "the person from @image1 in the setting from @image3" ``` ```json { "scene": "Overall setting description", "subjects": [ { "type": "Subject category", "description": "Physical attributes and details", "pose": "Action or stance", "position": "foreground/midground/background" } ], "style": "Artistic rendering approach", "color_palette": ["color1", "color2", "color3"], "lighting": "Lighting conditions and direction", "mood": "Emotional atmosphere", "composition": "rule of thirds/centered/dynamic diagonal", "camera": { "angle": "eye level/low angle/high angle", "distance": "close-up/medium shot/wide shot", "lens": "35mm/50mm/85mm" } } ``` -------------------------------- ### Basic API Call (CURL) Source: https://vsegpt.ru/Docs/API/Code A fundamental example demonstrating how to make a basic API call using CURL. This snippet is useful for getting started with text generation. ```bash curl -X POST "https://api.vsegpt.ai/v1/chat/completions" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o-mini", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"} ] }' ``` -------------------------------- ### Python Tool Call Example (Recommended) Source: https://vsegpt.ru/Docs/API/AddFeatures This example shows how to use the recommended tool calls feature, which is compatible with OpenAI and other models supporting the OpenAI format. It defines a tool with a function and passes it to the ChatCompletion API. ```python # prompt = "What is the weather like in Boston?" messages = [] #messages.append({"role": "system", "content": system_text}) messages.append({"role": "user", "content": prompt}) response = openai.ChatCompletion.create( model="openai/gpt-3.5-turbo", messages =messages, temperature=0.1, n=1, max_tokens = 1500, stream=False, tool_choice="auto", tools = [{ "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, }, "required": ["location"], }, }, } ] ) ``` -------------------------------- ### Third-Party Libraries and Examples (TypeScript) Source: https://vsegpt.ru/Docs/API/Code A TypeScript example for interacting with the Vsegpt API. Suitable for modern JavaScript development, including Node.js and browser applications. ```typescript import axios from 'axios'; const apiKey = 'YOUR_API_KEY'; const apiUrl = 'https://api.vsegpt.ai/v1/chat/completions'; async function getCompletion(prompt: string): Promise { try { const response = await axios.post(apiUrl, { model: 'gpt-4o-mini', messages: [ {role: 'system', content: 'You are a helpful assistant.'}, {role: 'user', content: prompt} ] }, { headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' } }); return response.data.choices[0].message.content; } catch (error) { console.error('Error:', error); throw error; } } getCompletion('Hello!').then(content => console.log(content)); ``` -------------------------------- ### Generate Video from Image (Image-to-Video) (Python) Source: https://vsegpt.ru/Docs/API/Code Example of generating video content from an input image using the Vsegpt API. This allows for animating static images. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") response = client.videos.generate_from_image( image=open("path/to/your/image.png", "rb"), prompt="Animate this image to show a gentle breeze blowing through the trees.", model="image-to-video", size="720p", fps=24 ) video_url = response.data[0].url print(video_url) ``` -------------------------------- ### Generate Music (Text-to-Audio) (Python) Source: https://vsegpt.ru/Docs/API/Code Example of generating music from text prompts using the Vsegpt API. This feature allows for creating custom audio tracks. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") response = client.audio.generate_music( prompt="Uplifting electronic music with a driving beat", model="text-to-audio", duration_seconds=30 ) audio_url = response.data[0].url print(audio_url) ``` -------------------------------- ### Dialogue Support (Python) Source: https://vsegpt.ru/Docs/API/Code Example of how to maintain a conversation history for dialogue support using the Vsegpt API in Python. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") messages = [ {"role": "system", "content": "You are a helpful assistant."} ] while True: user_input = input("User: ") if user_input.lower() == 'exit': break messages.append({"role": "user", "content": user_input}) response = client.chat.completions.create( model="gpt-4o-mini", messages=messages ) assistant_message = response.choices[0].message.content print(f"Assistant: {assistant_message}") messages.append({"role": "assistant", "content": assistant_message}) ``` -------------------------------- ### Libraries for Other Languages (Go) Source: https://vsegpt.ru/Docs/API/Code Information and potential examples for using a Vsegpt library for the Go programming language. Useful for Go developers integrating with the API. ```go // Example using a hypothetical Go client library // package main // // import ( // "fmt" // "log" // "your_vsegpt_go_library" // ) // // func main() { // client := your_vsegpt_go_library.NewClient("YOUR_API_KEY") // // resp, err := client.Chat.Completions(context.Background(), &your_vsegpt_go_library.ChatCompletionRequest{ // Model: "gpt-4o-mini", // Messages: []your_vsegpt_go_library.Message{ // {Role: "system", Content: "You are a helpful assistant."}, // {Role: "user", Content: "Hello!"}, // }, // }) // if err != nil { // log.Fatalf("Error: %v", err) // } // // fmt.Println(resp.Choices[0].Message.Content) // } ``` -------------------------------- ### Speech Recognition (Python) Source: https://vsegpt.ru/Docs/API/Code Example of using the Vsegpt API for speech recognition (Speech-to-Text). This converts audio input into text. ```python from vsegpt import Vsegpt client = Vsegpt("YOUR_API_KEY") with open("path/to/your/audio.wav", "rb") as audio_file: transcript = client.audio.transcriptions.create( model="whisper-1", file=audio_file ) print(transcript.text) ``` -------------------------------- ### DeepSeek V3.2 671B Example Source: https://vsegpt.ru/Docs/ModelsNew An updated version of DeepSeek V3.1 featuring a new architecture for lower cost and comparable quality. Supports tools in the standard OpenAI format. ```json { "model": "deepseek-v3.2-671b", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Translate 'Hello, world!' to French."} ], "tools": [ { "type": "function", "function": { "name": "translate_text", "description": "Translates text from one language to another", "parameters": { "type": "object", "properties": { "text": { "type": "string", "description": "The text to translate" }, "target_language": { "type": "string", "description": "The language to translate to" } }, "required": ["text", "target_language"] } } } ], "tool_choice": "auto" } ``` -------------------------------- ### OpenAI GPT-5.1 Codex Max Example Source: https://vsegpt.ru/Docs/ModelsNew This model is designed for long-term software development tasks with high context. It supports tools and structured outputs in the standard OpenAI format. Maximum output generation size is 128,000 tokens. ```json { "model": "gpt-5.1-codex-max", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Write a Python function to calculate the factorial of a number."} ], "tools": [ { "type": "function", "function": { "name": "calculate_factorial", "description": "Calculates the factorial of a non-negative integer", "parameters": { "type": "object", "properties": { "number": { "type": "integer", "description": "The non-negative integer to calculate the factorial for" } }, "required": ["number"] } } } ], "tool_choice": "auto" } ``` -------------------------------- ### DeepSeek V3.2 Speciale 671B Example Source: https://vsegpt.ru/Docs/ModelsNew A special version of DeepSeek with enhanced reasoning quality, known for its performance in math and computer science competitions. Supports tools in the standard OpenAI format. ```json { "model": "deepseek-v3.2-speciale-671b", "messages": [ {"role": "system", "content": "You are a math expert."}, {"role": "user", "content": "Solve the following equation: 2x + 5 = 15"} ], "tools": [ { "type": "function", "function": { "name": "solve_equation", "description": "Solves a linear equation", "parameters": { "type": "object", "properties": { "equation": { "type": "string", "description": "The equation to solve" } }, "required": ["equation"] } } } ], "tool_choice": "auto" } ``` -------------------------------- ### DeepSeek V3.2 671B (Thinking) Example Source: https://vsegpt.ru/Docs/ModelsNew An updated version of DeepSeek V3.1 with a new architecture, offering reduced cost and similar quality. This version is optimized for reasoning and supports tools in the standard OpenAI format. ```json { "model": "deepseek-v3.2-671b-thinking", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain the concept of recursion."} ], "tools": [ { "type": "function", "function": { "name": "explain_concept", "description": "Explains a given concept", "parameters": { "type": "object", "properties": { "concept": { "type": "string", "description": "The concept to explain" } }, "required": ["concept"] } } } ], "tool_choice": "auto" } ``` -------------------------------- ### Test Structured Outputs with JSON Schema Source: https://vsegpt.ru/Docs/API/AddFeatures Demonstrates how to use structured outputs with a JSON schema for a math tutor prompt. This example requires the 'openai' library and specifies a detailed schema for the response. ```python def test_structured_outputs(model:str) -> dict: math_tutor_prompt = ''' You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning. ''' prompt = "There are equation 'x+3=8'. Find the integer 'x'" messages = [] messages.append({"role": "system", "content": math_tutor_prompt}) messages.append({"role": "user", "content": prompt}) response = openai.ChatCompletion.create( headers={ "X-Title": "Test structured outputs" }, model=model, messages=messages, temperature=0.1, n=1, max_tokens=500, response_format={ "type": "json_schema", "json_schema": { "name": "math_reasoning", "schema": { "type": "object", "properties": { "steps": { "type": "array", "items": { "type": "object", "properties": { "explanation": {"type": "string"}, "output": {"type": "string"} }, "required": ["explanation", "output"], "additionalProperties": False } }, "final_answer": {"type": "integer"} }, "required": ["steps", "final_answer"], "additionalProperties": False }, "strict": True } } ) print("Response:", response) response1 = response["choices"][0]["message"] # будет содержать content, в котором нужный JSON со структурой # response_text: str = str(response1).strip() return response1 ``` -------------------------------- ### Python Function Call Example (Deprecated) Source: https://vsegpt.ru/Docs/API/AddFeatures This example demonstrates how to use the deprecated function calls feature with OpenAI models. It shows how to define a function and pass it to the ChatCompletion API. ```python # prompt = "What is the weather like in Boston?" messages = [] #messages.append({"role": "system", "content": system_text}) messages.append({"role": "user", "content": prompt}) response = openai.ChatCompletion.create( model="openai/gpt-3.5-turbo", # model="jondurbin/airoboros-l2-70b", messages =messages, temperature=0.9, n=1, max_tokens = 1500, stream=stream, functions=[ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"] } }, "required": ["location"] } } ] ) ``` -------------------------------- ### C# Async API Call Source: https://vsegpt.ru/Docs/API/Code This C# example shows how to make an asynchronous API call to VseGPT using HttpClient. It includes setting up the request with messages, model, and other parameters, and handling the response. ```csharp static async Task Main() { string apiKey = "sk-or-vv-86*************"; // ваш ключ в VseGPT после регистрации string baseApiUrl = "https://api.vsegpt.ru/v1/"; string prompt = "Напиши последовательно числа от 1 до 10"; try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); List messages = new List(); messages.Add(new { role = "user", content = prompt }); var requestData = new { model = "openai/gpt-4o-mini", messages = messages, temperature = 0.7, n = 1, max_tokens = Convert.ToInt32(prompt.Length * 1.5), extra_headers = new { X_Title = "My App" } // опционально - передача информации об источнике API-вызова }; var jsonRequest = Newtonsoft.Json.JsonConvert.SerializeObject(requestData); var content = new StringContent(jsonRequest, Encoding.UTF8, "application/json"); var response = await client.PostAsync(baseApiUrl + "chat/completions", content); if (response.IsSuccessStatusCode) { var jsonResponse = await response.Content.ReadAsStringAsync(); dynamic responseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonResponse); string responseContent = responseData.choices[0].message.content; Console.WriteLine("Response: " + responseContent); } else { Console.WriteLine("Error: " + response.ReasonPhrase); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } } ``` -------------------------------- ### Working with Large Text - RAG Example (Google Colab) Source: https://vsegpt.ru/Docs/API/Code An example in Google Colab demonstrating Retrieval-Augmented Generation (RAG) for searching a knowledge base using embeddings. This is useful for question-answering on custom data. ```python # Install necessary libraries !pip install vsegpt langchain-community from vsegpt import Vsegpt from langchain_community.embeddings import VsegptEmbeddings from langchain_community.vectorstores import FAISS from langchain_core.documents import Document client = Vsegpt("YOUR_API_KEY") # Sample knowledge base knowledge_base = [ "Vsegpt is a powerful AI model.", "It supports various tasks like text generation and embeddings.", "RAG stands for Retrieval-Augmented Generation." ] # Generate embeddings embeddings = VsegptEmbeddings(client=client, model="text-embedding-ada-002") # Create a vector store documents = [Document(page_content=text) for text in knowledge_base] vector_store = FAISS.from_documents(documents, embeddings) # Query the knowledge base query = "What is Vsegpt?" results = vector_store.similarity_search(query) # Use the retrieved information to generate an answer (simplified) context = " ".join([doc.page_content for doc in results]) response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": f"Use the following context to answer the question. Context: {context}"}, {"role": "user", "content": query} ] ) print(response.choices[0].message.content) ```