Skip to content

Commit e9e56b3

Browse files
committed
Merge branch 'alpha' into refactoring_4
2 parents e54ed4f + ef63270 commit e9e56b3

30 files changed

+1538
-21
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Keys
2+
3+
This document provides a concise example of an environment configuration script, used to set up environment variables for a project. These variables configure application behavior without altering the code.
4+
5+
## Example of `.key/-env.sh`
6+
7+
```bash
8+
# OpenAI API key.
9+
OPENAI_API_KEY=sk-proj-ABCDEFG
10+
```
11+
12+
## How to Use in Shell
13+
14+
To apply these variables to your current shell session, use:
15+
16+
```bash
17+
. ./key/-env.sh
18+
```
19+
20+
This command sources the script, making the variables available in your current session. Ensure `-env.sh` is in the `key` directory relative to your current location.

module/move/assistant/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Assist AI in writing code.
1515
"""
1616
categories = [ "algorithms", "development-tools" ]
1717
keywords = [ "fundamental", "general-purpose" ]
18+
default-run = "main"
1819

1920
[lints]
2021
workspace = true
@@ -32,6 +33,14 @@ enabled = [
3233
"reflect_tools/enabled",
3334
]
3435

36+
[[bin]]
37+
name = "main"
38+
path = "src/bin/main.rs"
39+
40+
[[bin]]
41+
name = "list_resources"
42+
path = "src/bin/list_resources.rs"
43+
3544
[dependencies]
3645
# xxx : qqq : optimze features
3746
mod_interface = { workspace = true, features = [ "full" ] }
@@ -41,6 +50,12 @@ reflect_tools = { workspace = true, features = [ "full" ] }
4150
openai-api-rs = { version = "=5.0.11" }
4251
tokio = { version = "1", features = ["full"] }
4352
dotenv = "0.15"
53+
clap = { version = "4.5.20", features = ["derive"] }
54+
pth = "0.21.0"
55+
serde = { version = "1.0.213", features = ["derive"] }
56+
serde_with = "3.11.0"
57+
error_tools = "0.17.0"
58+
derive_tools = { version = "0.32.0", features = ["full"] }
4459

4560
[dev-dependencies]
4661
test_tools = { workspace = true }
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Commands
2+
3+
## Legend
4+
5+
- `<...>` - argument.
6+
- `<..?>` - optional argument.
7+
- `<...=...>` - argument with default value.
8+
- `(...)+` - one or more times.
9+
10+
## OpenAI
11+
12+
### Files
13+
14+
```shell
15+
assistant openai files upload <path> <purpose>
16+
assistant openai files list
17+
assistant openai files retrieve <id>
18+
assistant openai files delete <id>
19+
assistant openai files retrieve-content <id>
20+
```
21+
22+
### Assistants
23+
24+
```shell
25+
assistant openai assistants create <model> <name?> <description?> <instructions?>
26+
assistant openai assistants list
27+
assistant openai assistants retrieve <id>
28+
assistant openai assistants modify <id> <model?> <name?> <description?> <instructions?>
29+
assistant openai assistants delete <id>
30+
```
31+
32+
### Threads
33+
34+
```shell
35+
assistant openai threads create
36+
assistant openai threads retrieve <id>
37+
assistant openai threads delete <id>
38+
```
39+
40+
### Messages
41+
42+
```shell
43+
assistant openai messages create <thread_id> <role> <content>
44+
assistant openai messages list <thread_id>
45+
assistant openai messages retrieve <thread_id> <message_id>
46+
assistant openai messages modify <thread_id> <message_id>
47+
assistant openai messages delete <thread_id> <message_id>
48+
```
49+
50+
### Chat
51+
52+
```shell
53+
assistant openai chat create-completion (<role> <message>)+
54+
```
55+
56+
### Runs
57+
58+
```shell
59+
assistant openai runs create <thread_id> <assistant_id>
60+
assistant openai runs create-with-thread <assistant_id> <user_message>
61+
assistant openai runs list <thread_id>
62+
assistant openai runs retrieve <thread_id> <run_id>
63+
assistant openai runs cancel <thread_id> <run_id>
64+
```
65+
66+
## Anthropic
67+
68+
### Messages
69+
70+
```shell
71+
assistant anthropic messages create (<role> <message>)+
72+
```
73+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: OpenAI API
3+
---
4+
erDiagram
5+
File {
6+
string id PK
7+
string object
8+
integer bytes
9+
integer created_at
10+
string file_name
11+
string purpose
12+
}
13+
14+
Assistant {
15+
string id PK
16+
string object
17+
string model
18+
integer created_at
19+
string name
20+
string description
21+
string instructions
22+
tool[] tools
23+
metadata metadata
24+
headers headers
25+
}
26+
27+
Thread {
28+
string id PK
29+
string object
30+
integer created_at
31+
object tool_resources
32+
metadata metadata
33+
}
34+
35+
Message {
36+
string id PK
37+
string object
38+
integer created_at
39+
string thread_id FK
40+
string status
41+
object incomplete_details
42+
integer completed_at
43+
integer incomplete_at
44+
string role
45+
array content
46+
string assistant_id FK
47+
string run_id FK
48+
array attachments
49+
metadata metadata
50+
}
51+
52+
Run {
53+
string id PK
54+
string object
55+
integer created_at
56+
string thread_id FK
57+
string assistant_id FK
58+
string status
59+
object required_action
60+
object last_error
61+
integer expires_at
62+
integer started_at
63+
integer cancelled_at
64+
integer failed_at
65+
integer completed_at
66+
object incomplete_details
67+
string model
68+
string instructions
69+
tool[] tools
70+
metadata metadata
71+
headers headers
72+
}
73+
74+
Assistant |o--o{ Run : ""
75+
76+
Thread ||--o{ Message : ""
77+
Thread ||--o{ Run: ""
78+
546 KB
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Scenarios
2+
3+
## OpenAI
4+
5+
### Assistants
6+
7+
#### Make new assistant
8+
9+
```shell
10+
assistant openai assistants create gpt-4o-mini CoolBot 'CoolBot is a helpful assistant.' 'You are a helpful assistant.'
11+
```
12+
13+
This command will return assistant ID.
14+
15+
#### Chat with the assistant
16+
17+
To chat with OpenAI assistant, one should do this:
18+
19+
1. Create a thread. Thread is like a chat.
20+
2. Write a message in thread (e.g. a question).
21+
3. Run the assistant in the thread.
22+
23+
```shell
24+
assistant openai threads create
25+
```
26+
27+
This command will return the new thread ID (referred as `thread_id`). To call an assistant, you need to know its ID.
28+
29+
```shell
30+
assistant openai messages create <thread_id> user '2 + 2 = ?'
31+
assistant openai runs create <thread_id> <assistant_id>
32+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//!
2+
//! CLI actions of the tool.
3+
//!
4+
5+
mod private {}
6+
7+
crate::mod_interface!
8+
{
9+
layer openai;
10+
layer openai_assistants_list;
11+
layer openai_files_list;
12+
layer openai_runs_list;
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//!
2+
//! OpenAI API actions.
3+
//!
4+
//! This module also contains the definition of OpenAI Error.
5+
//!
6+
7+
mod private
8+
{
9+
10+
use error_tools::typed::Error;
11+
use derive_tools::{ AsRefStr };
12+
13+
use crate::*;
14+
use ser::DisplayFromStr;
15+
16+
/// Collective enum for errors in OpenAI actions.
17+
#[ ser::serde_as ]
18+
#[ derive( Debug, Error, AsRefStr, ser::Serialize ) ]
19+
#[ serde( tag = "type", content = "data" ) ]
20+
pub enum Error
21+
{
22+
/// API error from the underlying implementation crate.
23+
#[ error( "OpenAI API returned error:\n{0}" ) ]
24+
ApiError
25+
(
26+
#[ from ]
27+
#[ serde_as( as = "DisplayFromStr" ) ]
28+
openai_api_rs::v1::error::APIError
29+
)
30+
}
31+
32+
/// Shorthand for `Result` in OpenAI actions.
33+
pub type Result< T > = core::result::Result< T, Error >;
34+
35+
}
36+
37+
crate::mod_interface!
38+
{
39+
own use
40+
{
41+
Error,
42+
Result
43+
};
44+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//!
2+
//! List assistants in OpenAI API (action part).
3+
//!
4+
5+
mod private
6+
{
7+
8+
use std::fmt;
9+
10+
use format_tools::
11+
{
12+
AsTable,
13+
TableFormatter,
14+
output_format,
15+
};
16+
17+
use crate::*;
18+
use client::Client;
19+
use debug::AssistantObjectWrap;
20+
use actions::openai::Result;
21+
22+
/// Report for `openai assistants list`.
23+
#[ derive( Debug ) ]
24+
pub struct ListReport
25+
{
26+
/// Show records as separate tables.
27+
pub show_records_as_tables : bool,
28+
29+
/// OpenAI assistants.
30+
pub assistants: Vec< AssistantObjectWrap >
31+
}
32+
33+
impl fmt::Display for ListReport
34+
{
35+
fn fmt
36+
(
37+
&self,
38+
f : &mut fmt::Formatter< '_ >
39+
) -> fmt::Result
40+
{
41+
if self.show_records_as_tables
42+
{
43+
writeln!(f, "{}", AsTable::new( &self.assistants ).table_to_string_with_format( &output_format::Records::default() ) )
44+
}
45+
else
46+
{
47+
writeln!(f, "{}", AsTable::new( &self.assistants ).table_to_string_with_format( &output_format::Table::default() ) )
48+
}
49+
}
50+
}
51+
52+
/// List OpenAI assistants action.
53+
pub async fn action
54+
(
55+
client : &Client,
56+
show_records_as_tables : bool,
57+
) -> Result < ListReport >
58+
{
59+
let response = client.list_assistant( None, None, None, None ).await?;
60+
let assistants = response.data.into_iter().map( AssistantObjectWrap ).collect();
61+
Ok( ListReport { show_records_as_tables, assistants } )
62+
}
63+
}
64+
65+
crate::mod_interface!
66+
{
67+
own use action;
68+
}

0 commit comments

Comments
 (0)