openaiassistant 1.0.4 openaiassistant: ^1.0.4 copied to clipboard
A wrapper package for OpenAI assistant by Abel V. Massaley
OpenAI Assistant Flutter SDK #
Power your flutter app with the Assistants API from OpenAI that is designed to help developers build powerful AI assistants capable of performing a variety of tasks. (UNOFFICIAL PACKAGE)
How Assistants Work (Beta) #
The Assistants API is designed to help developers build powerful AI assistants capable of performing a variety of tasks.
Note: The Assistants API is currently in beta, and we are actively working on adding more functionality. Feel free to share your feedback in our Developer Forum.
Key Features of Assistants:
- Assistants can call OpenAI’s models with specific instructions to tune their personality and capabilities.
- Assistants can access multiple tools in parallel, including both OpenAI-hosted tools (e.g., Code interpreter and Knowledge retrieval) and tools you build/host via Function calling.
- Assistants can leverage persistent Threads to simplify AI application development. Threads store message history and truncate it when the conversation becomes too long for the model’s context length. Create a Thread once and append Messages to it as users reply.
- Assistants can work with Files in various formats, either as part of their creation or as part of Threads between Assistants and users. When using tools, Assistants can create files (e.g., images, spreadsheets, etc.) and cite files they reference in the Messages they create.
Installation #
Add the following line to your pubspec.yaml:
.
dependecies:
assistant_openai: ^1.0.1
Initialization #
Import and use anywhere in your project
import 'package:assistant_openai/openaiassistant.dart';
var client = OpenAIAssistant(apiKey: 'YOUR_OPENAI_API_KEY', organizationID: 'YOUR_ORGANIZATION_ID');
To Create an Assistant #
///CREATE A VARIABLE WITH NEW ASSISTANT OBJECT
var newAssistant = NewAssistantModel(
name: "ASSISTANT_NAME",
description: "My Math assistant",
instructions: "You are a math tutor",
model: "gpt-4",
tools: [
Tool(type: "retrieval")
],
fileIds: ['fieldID'],
);
///USE THE CLIENT TO ACCESS THE ASSISTANT CREATE MODULE AND PARSE THE NEW ASSISTANT OBJECT YOU CREATED
var assistant = await client.assistant.create(newAssistant);
///YOU GET BACK THE FOLLOWING VALUES FROM THE RESPONSE
print(assistant!.name);
print(assistant.model);
print(assistant.instructions);
print(assistant.tools);
print(assistant.fileIds);
print(assistant.description);
print(assistant.metadata);
To Retrieve an Assistant #
///USE THE CLIENT TO ACCESS THE ASSISTANT MODULE AND CALL THE RETRIEVE METHOD
var retrievedAssistant = await client.assistant.retrieve('PARSE_ASSISTANT_ID_HERE');
///YOU GET BACK THE FOLLOWING VALUES FROM THE RESPONSE
print(assistant!.name);
print(assistant.model);
print(assistant.instructions);
print(assistant.tools);
print(assistant.fileIds);
print(assistant.description);
print(assistant.metadata);
To Modify an Assistant #
///USE THE CLIENT TO ACCESS THE ASSISTANT MODULE AND CALL THE MODIFY METHOD
var assistantDetails = AssistantModel(
id: "ASSISTANT_ID",
name: "ASSISTANT_NAME",
description: "My Math assistant",
instructions: "You are a math tutor",
model: "gpt-4",
object: "assistant",
fileIds: ['fieldID'],
createdAt: INT,
tools: [],
metadata: Map<dynamic, dynamic>,
);
var assistant = await client.assistant.modify(assistantDetails);
///YOU GET BACK THE FOLLOWING VALUES FROM THE RESPONSE
print(assistant!.name);
print(assistant.model);
print(assistant.instructions);
print(assistant.tools);
print(assistant.fileIds);
print(assistant.description);
print(assistant.metadata);
Contributing #
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Or connect with me on GITHUB | INSTAGRAM
About Me #
A Software Engineer Living in Seoul, South Korea
Please make sure to update tests as appropriate.