yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
openai_ai_service.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_OPENAI_AI_SERVICE_H_
2#define YAZE_SRC_CLI_OPENAI_AI_SERVICE_H_
3
4#include <string>
5#include <vector>
6
7#include "absl/status/status.h"
8#include "absl/status/statusor.h"
10
11#ifdef YAZE_AI_RUNTIME_AVAILABLE
13#endif
14
15namespace yaze {
16namespace cli {
17
19 std::string api_key;
20 std::string model = "gpt-4o-mini"; // Default to cost-effective model
21 float temperature = 0.7f;
23 std::string system_instruction;
25 std::string prompt_version = "v3";
26 bool verbose = false;
27
28 OpenAIConfig() = default;
29 explicit OpenAIConfig(const std::string& key) : api_key(key) {}
30};
31
32#ifdef YAZE_AI_RUNTIME_AVAILABLE
33
34class OpenAIAIService : public AIService {
35 public:
36 explicit OpenAIAIService(const OpenAIConfig& config);
37 void SetRomContext(Rom* rom) override;
38
39 // Primary interface
40 absl::StatusOr<AgentResponse> GenerateResponse(
41 const std::string& prompt) override;
42 absl::StatusOr<AgentResponse> GenerateResponse(
43 const std::vector<agent::ChatMessage>& history) override;
44
45 // Health check
46 absl::Status CheckAvailability();
47
48 // List available models from OpenAI API
49 absl::StatusOr<std::vector<ModelInfo>> ListAvailableModels() override;
50
51 std::string GetProviderName() const override { return "openai"; }
52
53 // Function calling support
54 void EnableFunctionCalling(bool enable = true);
55 std::vector<std::string> GetAvailableTools() const;
56
57 private:
58 std::string BuildSystemInstruction();
59 std::string BuildFunctionCallSchemas();
60 absl::StatusOr<AgentResponse> ParseOpenAIResponse(
61 const std::string& response_body);
62
63 bool function_calling_enabled_ = true;
64
65 OpenAIConfig config_;
66 PromptBuilder prompt_builder_;
67};
68
69#else // !YAZE_AI_RUNTIME_AVAILABLE
70
71// Stub implementation when AI runtime is disabled
72class OpenAIAIService : public AIService {
73 public:
74 explicit OpenAIAIService(const OpenAIConfig&) {}
75 void SetRomContext(Rom*) override {}
76 absl::StatusOr<AgentResponse> GenerateResponse(
77 const std::string& prompt) override {
78 return absl::FailedPreconditionError(
79 "OpenAI AI runtime is disabled (prompt: " + prompt + ")");
80 }
81 absl::StatusOr<AgentResponse> GenerateResponse(
82 const std::vector<agent::ChatMessage>&) override {
83 return absl::FailedPreconditionError("OpenAI AI runtime is disabled");
84 }
85 absl::Status CheckAvailability() {
86 return absl::FailedPreconditionError("OpenAI AI runtime is disabled");
87 }
89 std::vector<std::string> GetAvailableTools() const { return {}; }
90 absl::StatusOr<std::vector<ModelInfo>> ListAvailableModels() override {
91 return absl::FailedPreconditionError("OpenAI AI runtime is disabled");
92 }
93 std::string GetProviderName() const override { return "openai"; }
94};
95
96#endif // YAZE_AI_RUNTIME_AVAILABLE
97
98} // namespace cli
99} // namespace yaze
100
101#endif // YAZE_SRC_CLI_OPENAI_AI_SERVICE_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
absl::StatusOr< AgentResponse > GenerateResponse(const std::vector< agent::ChatMessage > &) override
absl::StatusOr< AgentResponse > GenerateResponse(const std::string &prompt) override
absl::StatusOr< std::vector< ModelInfo > > ListAvailableModels() override
void SetRomContext(Rom *) override
std::string GetProviderName() const override
OpenAIAIService(const OpenAIConfig &)
std::vector< std::string > GetAvailableTools() const
OpenAIConfig(const std::string &key)