Skip to content

Commit d06f035

Browse files
committed
assistant : evolve
1 parent 8d66c4f commit d06f035

File tree

11 files changed

+215
-120
lines changed

11 files changed

+215
-120
lines changed

module/core/format_tools/src/format/table.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ mod private
175175
// Self::Row : 'a;
176176
}
177177

178-
impl< T, RowKey, Row, CellKey >
179-
TableRows<>
178+
impl< T, RowKey, Row, CellKey > TableRows<>
180179
for AsTable< '_, T, RowKey, Row, CellKey >
181180
where
182181

module/core/format_tools/tests/inc/tabe_foreign_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn iterator_over_objects_without_impl()
3030
output_format,
3131
};
3232

33+
// xxx : Clone should not be required
3334
#[ derive( Debug, Clone ) ]
3435
pub struct TestObjecWrap( TestObjectWithoutImpl );
3536

module/core/reflect_tools/src/reflect/fields/vec.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use collection_tools::Vec;
99
impl< V, Borrowed > Fields< usize, &'_ Borrowed > for Vec< V >
1010
where
1111
Borrowed : std::borrow::ToOwned + 'static + ?Sized,
12+
// Borrowed : ?Sized + 'static,
1213
V : std::borrow::Borrow< Borrowed >,
1314
{
1415

@@ -28,6 +29,7 @@ where
2829
impl< V, Borrowed > Fields< usize, Option< Cow< '_, Borrowed > > > for Vec< V >
2930
where
3031
Borrowed : std::borrow::ToOwned + 'static + ?Sized,
32+
// Borrowed : ?Sized + 'static,
3133
V : std::borrow::Borrow< Borrowed >,
3234
{
3335

@@ -39,6 +41,7 @@ where
3941

4042
fn fields< 's >( &'s self ) -> impl IteratorTrait< Item = ( Self::Key< 's >, Self::Val< 's > ) >
4143
{
44+
// self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( &val ) ) ) )
4245
self.iter().enumerate().map( move | ( key, val ) | ( key, Some( Cow::Borrowed( val.borrow() ) ) ) )
4346
}
4447

@@ -47,6 +50,7 @@ where
4750
impl< V, Borrowed, Marker > Fields< usize, OptionalCow< '_, Borrowed, Marker > > for Vec< V >
4851
where
4952
Borrowed : std::borrow::ToOwned + 'static + ?Sized,
53+
// Borrowed : ?Sized + 'static,
5054
V : std::borrow::Borrow< Borrowed >,
5155
Marker : Clone + Copy + 'static,
5256
{

module/move/assistant/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ enabled = [
3434

3535
[dependencies]
3636
# xxx : qqq : optimze features
37+
mod_interface = { workspace = true, features = [ "full" ] }
3738
former = { workspace = true, features = [ "full" ] }
3839
format_tools = { workspace = true, features = [ "full" ] }
3940
reflect_tools = { workspace = true, features = [ "full" ] }
40-
openai-api-rs = { version = "4.0.9" }
41+
openai-api-rs = { version = "=5.0.11" }
4142
tokio = { version = "1", features = ["full"] }
4243
dotenv = "0.15"
4344

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# use REST Client VSCode plugin
2+
# ctrl+l
3+
14
get https://api.openai.com/v1/models
25
Authorization: Bearer {{openai_token}}
36
# Content-Type: application/json
7+
8+
get https://api.openai.com/v1/assistants
9+
Authorization: Bearer {{openai_token}}
10+
OpenAI-Beta: assistants=v2
11+
Content-Type: application/json

module/move/assistant/src/client.rs

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
mod private
77
{
88

9+
910
pub use openai_api_rs::v1::
1011
{
11-
api::Client,
12+
api::OpenAIClient as Client,
13+
// api::Client,
1214
assistant::AssistantObject,
1315
};
1416

@@ -32,65 +34,19 @@ mod private
3234
pub fn client() -> Result< Client, Box< dyn Error > >
3335
{
3436
let api_key = env::var( "OPENAI_API_KEY" )?;
37+
println!( "api_key : {}", api_key );
3538
Ok( Client::new( api_key ) )
3639
}
3740

38-
39-
}
40-
41-
#[ allow( unused_imports ) ]
42-
pub use own::*;
43-
44-
/// Own namespace of the module.
45-
#[ allow( unused_imports ) ]
46-
pub mod own
47-
{
48-
use super::*;
49-
50-
#[ doc( inline ) ]
51-
#[ allow( unused_imports ) ]
52-
pub use orphan::*;
53-
5441
}
5542

56-
/// Orphan namespace of the module.
57-
#[ allow( unused_imports ) ]
58-
pub mod orphan
43+
crate::mod_interface!
5944
{
60-
use super::*;
61-
#[ doc( inline ) ]
62-
#[ allow( unused_imports ) ]
63-
pub use exposed::*;
64-
}
65-
66-
/// Exposed namespace of the module.
67-
#[ allow( unused_imports ) ]
68-
pub mod exposed
69-
{
70-
use super::*;
71-
72-
#[ doc( inline ) ]
73-
pub use private::
45+
exposed use
7446
{
47+
Client,
7548
ClientOptions,
76-
client,
7749
AssistantObject,
50+
client,
7851
};
79-
80-
// #[ doc( inline ) ]
81-
// #[ allow( unused_imports ) ]
82-
// pub use reflect_tools::
83-
// {
84-
// Fields,
85-
// _IteratorTrait,
86-
// IteratorTrait,
87-
// };
88-
89-
}
90-
91-
/// Prelude to use essentials: `use my_module::prelude::*`.
92-
#[ allow( unused_imports ) ]
93-
pub mod prelude
94-
{
95-
use super::*;
9652
}

module/move/assistant/src/debug.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//!
2+
//! Client of API.
3+
//!
4+
5+
/// Internal namespace.
6+
mod private
7+
{
8+
9+
}
10+
11+
use format_tools::
12+
{
13+
Fields,
14+
TableWithFields,
15+
};
16+
use std::borrow::Cow;
17+
18+
mod assistant_object;
19+
mod file_data;
20+
21+
crate::mod_interface!
22+
{
23+
exposed use
24+
{
25+
assistant_object::AssistantObjectWrap,
26+
file_data::FileDataWrap,
27+
};
28+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use super::*;
2+
use openai_api_rs::v1::assistant;
3+
4+
/// A wrapper for `AssistantObject` to make pretty print.
5+
#[ derive( Debug ) ]
6+
pub struct AssistantObjectWrap( pub assistant::AssistantObject );
7+
8+
impl Clone for AssistantObjectWrap
9+
{
10+
fn clone( &self ) -> Self
11+
{
12+
// Manually clone each field of the wrapped AssistantObject
13+
AssistantObjectWrap( assistant::AssistantObject
14+
{
15+
id : self.0.id.clone(),
16+
object : self.0.object.clone(),
17+
created_at : self.0.created_at,
18+
name : self.0.name.clone(),
19+
description : self.0.description.clone(),
20+
model : self.0.model.clone(),
21+
instructions : self.0.instructions.clone(),
22+
tools : self.0.tools.clone(),
23+
tool_resources : self.0.tool_resources.clone(),
24+
metadata : self.0.metadata.clone(),
25+
headers : self.0.headers.clone(),
26+
} )
27+
}
28+
}
29+
30+
impl TableWithFields for AssistantObjectWrap {}
31+
impl Fields< &'_ str, Option< Cow< '_, str > > >
32+
for AssistantObjectWrap
33+
{
34+
type Key< 'k > = &'k str;
35+
type Val< 'v > = Option< Cow< 'v, str > >;
36+
37+
fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) >
38+
{
39+
use format_tools::ref_or_display_or_debug_multiline::field;
40+
let mut dst = Vec::new();
41+
42+
// Use the field! macro for direct field references
43+
dst.push( field!( &self.0.id ) );
44+
dst.push( field!( &self.0.object ) );
45+
dst.push( field!( &self.0.model ) );
46+
47+
// Manually handle fields that require function calls
48+
dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) );
49+
dst.push( ( "name", self.0.name.as_deref().map( Cow::Borrowed ) ) );
50+
dst.push( ( "description", self.0.description.as_deref().map( Cow::Borrowed ) ) );
51+
dst.push( ( "instructions", self.0.instructions.as_deref().map( Cow::Borrowed ) ) );
52+
53+
// Handle complex fields like `tools`, `tool_resources`, `metadata`, and `headers`
54+
if !self.0.tools.is_empty()
55+
{
56+
dst.push( ( "tools", Some( Cow::Borrowed( "tools present" ) ) ) );
57+
}
58+
else
59+
{
60+
dst.push( ( "tools", Option::None ) );
61+
}
62+
63+
if let Some( _metadata ) = &self.0.metadata
64+
{
65+
dst.push( ( "metadata", Some( Cow::Borrowed( "metadata present" ) ) ) );
66+
}
67+
else
68+
{
69+
dst.push( ( "metadata", Option::None ) );
70+
}
71+
72+
if let Some( _headers ) = &self.0.headers
73+
{
74+
dst.push( ( "headers", Some( Cow::Borrowed( "headers present" ) ) ) );
75+
}
76+
else
77+
{
78+
dst.push( ( "headers", Option::None ) );
79+
}
80+
81+
dst.into_iter()
82+
}
83+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
use super::*;
3+
use openai_api_rs::v1::file::FileData;
4+
5+
// Assuming the `format_tools` module and `field!` macro are defined elsewhere
6+
7+
/// A wrapper for `FileData` to make pretty print.
8+
#[ derive( Debug ) ]
9+
pub struct FileDataWrap( pub FileData );
10+
11+
impl Clone for FileDataWrap
12+
{
13+
fn clone( &self ) -> Self
14+
{
15+
FileDataWrap( FileData
16+
{
17+
id : self.0.id.clone(),
18+
object : self.0.object.clone(),
19+
bytes : self.0.bytes,
20+
created_at : self.0.created_at,
21+
filename : self.0.filename.clone(),
22+
purpose : self.0.purpose.clone(),
23+
} )
24+
}
25+
}
26+
27+
impl TableWithFields for FileDataWrap {}
28+
impl Fields< &'_ str, Option< Cow< '_, str > > >
29+
for FileDataWrap
30+
{
31+
type Key<'k> = &'k str;
32+
type Val< 'v > = Option< Cow< 'v, str > >;
33+
34+
fn fields( &self ) -> impl format_tools::IteratorTrait< Item = ( &'_ str, Option< Cow< '_, str > > ) >
35+
{
36+
use format_tools::ref_or_display_or_debug_multiline::field;
37+
let mut dst = Vec::new();
38+
39+
// Use the field! macro for direct field references
40+
dst.push( field!( &self.0.id ) );
41+
dst.push( field!( &self.0.object ) );
42+
dst.push( ( "bytes", Some( Cow::Owned( self.0.bytes.to_string() ) ) ) );
43+
dst.push( ( "created_at", Some( Cow::Owned( self.0.created_at.to_string() ) ) ) );
44+
dst.push( field!( &self.0.filename ) );
45+
dst.push( field!( &self.0.purpose ) );
46+
47+
dst.into_iter()
48+
}
49+
}

0 commit comments

Comments
 (0)