-
Notifications
You must be signed in to change notification settings - Fork 0
Language Reference ‐ AI Chat Library
The AI Chat Library for FBASIC empowers users to connect and interact with leading AI providers such as OpenAI, Claude, Gemini, Hugging Face, and custom setups (A developer can implement any other AI provider and connect it with this library), all from simple and intuitive statements. It allows programmers to define providers and models, create chat sessions with system prompts, send queries, and dynamically change providers for active sessions. This functionality streamlines the integration of conversational AI and large language models into FBASIC applications, enabling both low-code builders and advanced users to automate interactions, retrieve intelligent responses, and orchestrate AI-driven workflows with minimal scripting. As a result, developers can leverage state-of-the-art AI capabilities for problem-solving, content generation, and user assistance directly within a FBasic development environment.
The FBASIC AI Chat Library enables seamless integration with AI providers for conversational and generative tasks. It supports session management, dynamic provider switching, and prompt-response workflows.
| Statement Name | Syntax | Description |
|---|---|---|
| AIPROVIDER | AIPROVIDER provider_name, OPENAI|CLAUDE|GEMINI|HUGGINGFACE|DEEPSEEK|TEST, *|model | Sets up an AI provider with the selected type and model; use * for the provider's default. |
| AISESSION | AISESSION session_name, provider_name, system_prompt | Initializes an AI chat session tied to a provider, using a given system prompt for context. |
| AIPROMPT | AIPROMPT session_name, variable_response, prompt | Sends a prompt to the session and stores the AI's response in a variable for later use. |
| AISETPROVIDER | AISETPROVIDER session_name, provider_name | Changes the provider used for an existing AI chat session. |
-
Purpose: Set up an AI provider and select a model for use in a session.
-
Syntax:
AIPROVIDER provider_name, OPENAI|CLAUDE|GEMINI|HUGGINGFACE|DEEPSEEK|TEST, *|model
Note: The TEST provider is a fake provider that returns predefined texts. It is used for test/development purposes to avoid unwanted token sent.
-
Usage:
-
provider_name: User-defined identifier for the provider. -
<type>: Selects from supported AI services. -
*: Uses provider's default model. -
model: Specifies a custom model name.
-
-
Example:
AIPROVIDER MyProvider, OPENAI, * AIPROVIDER AltProvider, GEMINI, gemini-1.0-pro
-
Purpose: Initializes a new AI chat session with a specified provider and initial system prompt.
-
Syntax:
AISESSION session_name, provider_name, system_prompt
-
Usage:
-
session_name: Identifier for this session. -
provider_name: Must match a previously declared provider. -
system_prompt: Instructions or context for the AI.
-
-
Example:
AISESSION MainSession, MyProvider, "You are a helpful assistant."
-
Purpose: Sends a prompt over an active AI session and stores the AI's response.
-
Syntax:
AIPROMPT session_name, variable_response, prompt
-
Usage:
-
session_name: Target session identifier. -
variable_response: Variable to store the returned response. -
prompt: The message/question to send.
-
-
Example:
AIPROMPT MainSession, answer$, "What is the capital of Greece?" PRINT answer$
-
Purpose: Changes the AI provider for an existing session.
-
Syntax:
AISETPROVIDER session_name, provider_name
-
Usage:
-
session_name: Session whose provider is to be updated. -
provider_name: New provider to use.
-
-
Example:
AIPROVIDER MyProvider, OPENAI, * AISETPROVIDER MainSession, MyProvider
flowchart TD
A[AIPROVIDER<br/>Define AI provider and model] --> B[AISESSION<br/>Create AI session with provider and system prompt]
B --> C{Workflow}
C -->|Send a prompt| D[AIPROMPT<br/>Send prompt, store AI response]
C -->|Change provider| E[AISETPROVIDER<br/>Switch session to another provider]
D --> C
E --> C
AIPROVIDER MyProvider, OPENAI, *
AISESSION SupportSession, MyProvider, "Act as a customer support agent."
AIPROMPT SupportSession, reply, "How can I reset my password?"
PRINT reply
AIPROMPT SupportSession, reply, "What is the min. password length ?"
PRINT reply
- Providers and sessions must be initialized before use.
- Models are chosen at provider creation; switching providers may change session behavior.
- Multiple sessions and providers can be managed concurrently for advanced workflows.
To use the FBASIC AI Chat Library effectively, API keys from the respective AI providers are required. These keys authenticate your access to the AI services and must be obtained by registering with each provider. It is important to securely store and replace any placeholder API keys in your applications with your actual keys from the provider portals.
Moreover, many providers use a token-based billing system where each prompt sent to the AI and each response received consumes tokens from your allocated balance. It is crucial to monitor the input/output token balance associated with your API key to avoid service interruptions or unexpected charges. Ensuring you have sufficient tokens before making requests will guarantee smooth and continuous AI interactions.
| Provider | API Key Portal |
|---|---|
| OpenAI | https://platform.openai.com/api-keys |
| Gemini | https://makersuite.google.com/app/apikey |
| Claude | https://console.anthropic.com/ |
| Hugging Face | https://huggingface.co/settings/profile |
| DeekSeek | https://platform.deepseek.com/api_keys |
Important: Replace the placeholder (For interactive console program, appsettings.json) API keys with your actual keys from the above provider pages.
The API Key will be requested by the
AIPROVIDERstatement to theRequestForObjecthandler. For further information and details see the examples in the interactive console program.