diff --git a/packages/openai/Makefile b/packages/openai/Makefile new file mode 100644 index 00000000..f5cf22e6 --- /dev/null +++ b/packages/openai/Makefile @@ -0,0 +1,8 @@ +serialize-good: + cd rust/openai && cargo test serialize_good + +serialize-bad: + cd rust/openai && cargo test serialize_bad + +deserialize-good: + cd rust/openai && cargo test deserialize_good \ No newline at end of file diff --git a/packages/openai/response.json b/packages/openai/response.json new file mode 100644 index 00000000..da2a4c10 --- /dev/null +++ b/packages/openai/response.json @@ -0,0 +1,21 @@ +{ + "id": "12", + "object": "chat.completion", + "created": 1732752947, + "model": "gpt-4o-2024-08-06", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Once upon a time..." + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 11, + "completion_tokens": 661, + "total_tokens": 672 + } +} \ No newline at end of file diff --git a/packages/openai/rust/.gitignore b/packages/openai/rust/.gitignore new file mode 100644 index 00000000..5ac1cfa1 --- /dev/null +++ b/packages/openai/rust/.gitignore @@ -0,0 +1,3 @@ +target/ +.sdf/* +!.sdf/.wit/ \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/arrow/arrow.wit b/packages/openai/rust/.sdf/.wit/deps/arrow/arrow.wit new file mode 100644 index 00000000..f8aeeb2a --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/arrow/arrow.wit @@ -0,0 +1,151 @@ +package sdf:arrow; + +interface types { + + // arrow types + variant dtype { + %bool, + %i32, + %i64, + %float32, + %float64, + %string, + %timestamp, + %u8, + %u16, + %u32, + %u64, + %i8, + %i16, + } + + variant dvalue { + %bool(bool), + %i32(s32), + %i64(s64), + %float32(f32), + %float64(f64), + %string(string), + %timestamp(u64), + %u8(u8), + %u16(u16), + %u32(u32), + %u64(u64), + %i8(s8), + %i16(s16), + } +} + +// pass arrow data thru wasm boundary +interface wasm-io { + + use types.{ dtype }; + + record view { + offset: u32, + prefix: u32, + length: u32, + buffer-idx: u32, + } + + record utf8-view-array { + views: list, + buffers: list>, + len: u64, + bitmap: option> + } + + record bool-array { + values: tuple, u64>, + len: u64, + bitmap: option> + } + + record %u8-array { + values: list, + len: u64, + bitmap: option> + } + + record %u16-array { + values: list, + len: u64, + bitmap: option> + } + + record %u32-array { + values: list, + len: u64, + bitmap: option> + } + + record %u64-array { + values: list, + len: u64, + bitmap: option> + } + + record i8-array { + values: list, + len: u64, + bitmap: option> + } + + record i16-array { + values: list, + len: u64, + bitmap: option> + } + + record i32-array { + values: list, + len: u64, + bitmap: option> + } + + record i64-array { + values: list, + len: u64, + bitmap: option> + } + + record f32-array { + values: list, + len: u64, + bitmap: option> + } + + record f64-array { + values: list, + len: u64, + bitmap: option> + } + + // list of array chunks + variant array { + utf8(utf8-view-array), + i32(i32-array), + i64(i64-array), + %u8(%u8-array), + %f32(f32-array), + %f64(f64-array), + %bool(%bool-array), + i8(i8-array), + i16(i16-array), + %u16(%u16-array), + %u32(%u32-array), + %u64(%u64-array), + } + + type chunks = list; + + record column { + name: string, + chunks: chunks, + dtype: dtype + } + + record data-frame { + columns: list + } +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/df/deps/arrow/arrow.wit b/packages/openai/rust/.sdf/.wit/deps/df/deps/arrow/arrow.wit new file mode 100644 index 00000000..f8aeeb2a --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/df/deps/arrow/arrow.wit @@ -0,0 +1,151 @@ +package sdf:arrow; + +interface types { + + // arrow types + variant dtype { + %bool, + %i32, + %i64, + %float32, + %float64, + %string, + %timestamp, + %u8, + %u16, + %u32, + %u64, + %i8, + %i16, + } + + variant dvalue { + %bool(bool), + %i32(s32), + %i64(s64), + %float32(f32), + %float64(f64), + %string(string), + %timestamp(u64), + %u8(u8), + %u16(u16), + %u32(u32), + %u64(u64), + %i8(s8), + %i16(s16), + } +} + +// pass arrow data thru wasm boundary +interface wasm-io { + + use types.{ dtype }; + + record view { + offset: u32, + prefix: u32, + length: u32, + buffer-idx: u32, + } + + record utf8-view-array { + views: list, + buffers: list>, + len: u64, + bitmap: option> + } + + record bool-array { + values: tuple, u64>, + len: u64, + bitmap: option> + } + + record %u8-array { + values: list, + len: u64, + bitmap: option> + } + + record %u16-array { + values: list, + len: u64, + bitmap: option> + } + + record %u32-array { + values: list, + len: u64, + bitmap: option> + } + + record %u64-array { + values: list, + len: u64, + bitmap: option> + } + + record i8-array { + values: list, + len: u64, + bitmap: option> + } + + record i16-array { + values: list, + len: u64, + bitmap: option> + } + + record i32-array { + values: list, + len: u64, + bitmap: option> + } + + record i64-array { + values: list, + len: u64, + bitmap: option> + } + + record f32-array { + values: list, + len: u64, + bitmap: option> + } + + record f64-array { + values: list, + len: u64, + bitmap: option> + } + + // list of array chunks + variant array { + utf8(utf8-view-array), + i32(i32-array), + i64(i64-array), + %u8(%u8-array), + %f32(f32-array), + %f64(f64-array), + %bool(%bool-array), + i8(i8-array), + i16(i16-array), + %u16(%u16-array), + %u32(%u32-array), + %u64(%u64-array), + } + + type chunks = list; + + record column { + name: string, + chunks: chunks, + dtype: dtype + } + + record data-frame { + columns: list + } +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/df/df.wit b/packages/openai/rust/.sdf/.wit/deps/df/df.wit new file mode 100644 index 00000000..353b6c0d --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/df/df.wit @@ -0,0 +1,124 @@ +package sdf:df; + +interface df { + + use sdf:arrow/wasm-io.{ data-frame }; + + resource table-value { + get-data-frame: func() -> data-frame; + } + +} + +interface lazy { + + type index = u16; + + type expressions = list; + + // list of expr node based on https://datafusion.apache.org/user-guide/expressions.html + variant operation { + filter(expressions) + } + + // content of the each AST + variant expr { + binary(binary-exp), + col(column), + lit(lit), + } + + record binary-exp { + operator: operator, + left: index, + right: index + } + + + variant operator { + plus, + minus, + lt-eq, + eq, + gt + } + + record column { + name: string + } + + variant lit { + %string(string), + %f64(f64), + %f32(f32), + %i64(s64), + %i32(s32), + %i16(s16), + %i8(s8), + %u64(u64), + %u32(u32), + %u16(u16), + %u8(u8), + %bool(bool), + } + + record sort-options { + descending: list, + maintain-order: bool, + } + + record column-names { + names: list + } + + variant dtype { + %string, + %f64, + %f32, + %i64, + %i32, + %i16, + %i8, + %u64, + %u32, + %u16, + %u8, + %bool + } + + + record column-schema { + name: string, + index: u8, + schema: dtype + } + + // presents data frame as resource + resource df-value { + // find: static func(name: string) -> option; + run: func(ops: operation) -> result; + select: func(columns: column-names) -> result; + sort: func(columns: column-names, options: sort-options) -> result; + shape: func() -> tuple; + schema: func(columns: column-names) -> result,string>; + rows: func() -> result; + sql: func(sql: string) -> result; + head: func(rows: u64) -> result; + name: func() -> string; + } + + resource row-value { + end: func() -> bool; + next: func() -> bool; + index: func() -> s64; + skip: func(row: s64) -> bool; + value: func(col: u8) -> option; + } + + +} + +world arrow-world { + import df; + import lazy; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/df/df_test.wit b/packages/openai/rust/.sdf/.wit/deps/df/df_test.wit new file mode 100644 index 00000000..eff5aa1c --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/df/df_test.wit @@ -0,0 +1,20 @@ +package sdf:df; + + +interface test-df-guest { + use lazy.{ df-value }; + + init-df: func(df: df-value); + test-count: func() -> u64; + test-select: func() -> u64; + test-row: func() -> u64; + test-sort: func() -> u64; + test-sql: func() -> u64; + // test-row-resource: func() -> u64; +} + + +world test-df-world { + import lazy; + export test-df-guest; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/document-state/document.wit b/packages/openai/rust/.sdf/.wit/deps/document-state/document.wit new file mode 100644 index 00000000..d8d0da64 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/document-state/document.wit @@ -0,0 +1,18 @@ +package sdf:document-state; + +interface document { + + // holds document type + resource document-value { + get: func() -> list; + set: func(val: list); + } + + resource list-document { + get: func() -> list>>; + } +} + +world document-world { + import document; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/document-state/test.wit b/packages/openai/rust/.sdf/.wit/deps/document-state/test.wit new file mode 100644 index 00000000..b230f187 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/document-state/test.wit @@ -0,0 +1,14 @@ +package sdf:document-state; + +interface test-guest { + use document.{ document-value }; + + // initialize row resource + init-document: func(doc: document-value) ; + run: func(); + +} + +world test-world { + export test-guest; +} diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/arrow/arrow.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/arrow/arrow.wit new file mode 100644 index 00000000..f8aeeb2a --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/arrow/arrow.wit @@ -0,0 +1,151 @@ +package sdf:arrow; + +interface types { + + // arrow types + variant dtype { + %bool, + %i32, + %i64, + %float32, + %float64, + %string, + %timestamp, + %u8, + %u16, + %u32, + %u64, + %i8, + %i16, + } + + variant dvalue { + %bool(bool), + %i32(s32), + %i64(s64), + %float32(f32), + %float64(f64), + %string(string), + %timestamp(u64), + %u8(u8), + %u16(u16), + %u32(u32), + %u64(u64), + %i8(s8), + %i16(s16), + } +} + +// pass arrow data thru wasm boundary +interface wasm-io { + + use types.{ dtype }; + + record view { + offset: u32, + prefix: u32, + length: u32, + buffer-idx: u32, + } + + record utf8-view-array { + views: list, + buffers: list>, + len: u64, + bitmap: option> + } + + record bool-array { + values: tuple, u64>, + len: u64, + bitmap: option> + } + + record %u8-array { + values: list, + len: u64, + bitmap: option> + } + + record %u16-array { + values: list, + len: u64, + bitmap: option> + } + + record %u32-array { + values: list, + len: u64, + bitmap: option> + } + + record %u64-array { + values: list, + len: u64, + bitmap: option> + } + + record i8-array { + values: list, + len: u64, + bitmap: option> + } + + record i16-array { + values: list, + len: u64, + bitmap: option> + } + + record i32-array { + values: list, + len: u64, + bitmap: option> + } + + record i64-array { + values: list, + len: u64, + bitmap: option> + } + + record f32-array { + values: list, + len: u64, + bitmap: option> + } + + record f64-array { + values: list, + len: u64, + bitmap: option> + } + + // list of array chunks + variant array { + utf8(utf8-view-array), + i32(i32-array), + i64(i64-array), + %u8(%u8-array), + %f32(f32-array), + %f64(f64-array), + %bool(%bool-array), + i8(i8-array), + i16(i16-array), + %u16(%u16-array), + %u32(%u32-array), + %u64(%u64-array), + } + + type chunks = list; + + record column { + name: string, + chunks: chunks, + dtype: dtype + } + + record data-frame { + columns: list + } +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/deps/arrow/arrow.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/deps/arrow/arrow.wit new file mode 100644 index 00000000..f8aeeb2a --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/deps/arrow/arrow.wit @@ -0,0 +1,151 @@ +package sdf:arrow; + +interface types { + + // arrow types + variant dtype { + %bool, + %i32, + %i64, + %float32, + %float64, + %string, + %timestamp, + %u8, + %u16, + %u32, + %u64, + %i8, + %i16, + } + + variant dvalue { + %bool(bool), + %i32(s32), + %i64(s64), + %float32(f32), + %float64(f64), + %string(string), + %timestamp(u64), + %u8(u8), + %u16(u16), + %u32(u32), + %u64(u64), + %i8(s8), + %i16(s16), + } +} + +// pass arrow data thru wasm boundary +interface wasm-io { + + use types.{ dtype }; + + record view { + offset: u32, + prefix: u32, + length: u32, + buffer-idx: u32, + } + + record utf8-view-array { + views: list, + buffers: list>, + len: u64, + bitmap: option> + } + + record bool-array { + values: tuple, u64>, + len: u64, + bitmap: option> + } + + record %u8-array { + values: list, + len: u64, + bitmap: option> + } + + record %u16-array { + values: list, + len: u64, + bitmap: option> + } + + record %u32-array { + values: list, + len: u64, + bitmap: option> + } + + record %u64-array { + values: list, + len: u64, + bitmap: option> + } + + record i8-array { + values: list, + len: u64, + bitmap: option> + } + + record i16-array { + values: list, + len: u64, + bitmap: option> + } + + record i32-array { + values: list, + len: u64, + bitmap: option> + } + + record i64-array { + values: list, + len: u64, + bitmap: option> + } + + record f32-array { + values: list, + len: u64, + bitmap: option> + } + + record f64-array { + values: list, + len: u64, + bitmap: option> + } + + // list of array chunks + variant array { + utf8(utf8-view-array), + i32(i32-array), + i64(i64-array), + %u8(%u8-array), + %f32(f32-array), + %f64(f64-array), + %bool(%bool-array), + i8(i8-array), + i16(i16-array), + %u16(%u16-array), + %u32(%u32-array), + %u64(%u64-array), + } + + type chunks = list; + + record column { + name: string, + chunks: chunks, + dtype: dtype + } + + record data-frame { + columns: list + } +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/df.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/df.wit new file mode 100644 index 00000000..353b6c0d --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/df.wit @@ -0,0 +1,124 @@ +package sdf:df; + +interface df { + + use sdf:arrow/wasm-io.{ data-frame }; + + resource table-value { + get-data-frame: func() -> data-frame; + } + +} + +interface lazy { + + type index = u16; + + type expressions = list; + + // list of expr node based on https://datafusion.apache.org/user-guide/expressions.html + variant operation { + filter(expressions) + } + + // content of the each AST + variant expr { + binary(binary-exp), + col(column), + lit(lit), + } + + record binary-exp { + operator: operator, + left: index, + right: index + } + + + variant operator { + plus, + minus, + lt-eq, + eq, + gt + } + + record column { + name: string + } + + variant lit { + %string(string), + %f64(f64), + %f32(f32), + %i64(s64), + %i32(s32), + %i16(s16), + %i8(s8), + %u64(u64), + %u32(u32), + %u16(u16), + %u8(u8), + %bool(bool), + } + + record sort-options { + descending: list, + maintain-order: bool, + } + + record column-names { + names: list + } + + variant dtype { + %string, + %f64, + %f32, + %i64, + %i32, + %i16, + %i8, + %u64, + %u32, + %u16, + %u8, + %bool + } + + + record column-schema { + name: string, + index: u8, + schema: dtype + } + + // presents data frame as resource + resource df-value { + // find: static func(name: string) -> option; + run: func(ops: operation) -> result; + select: func(columns: column-names) -> result; + sort: func(columns: column-names, options: sort-options) -> result; + shape: func() -> tuple; + schema: func(columns: column-names) -> result,string>; + rows: func() -> result; + sql: func(sql: string) -> result; + head: func(rows: u64) -> result; + name: func() -> string; + } + + resource row-value { + end: func() -> bool; + next: func() -> bool; + index: func() -> s64; + skip: func(row: s64) -> bool; + value: func(col: u8) -> option; + } + + +} + +world arrow-world { + import df; + import lazy; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/df_test.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/df_test.wit new file mode 100644 index 00000000..eff5aa1c --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/df/df_test.wit @@ -0,0 +1,20 @@ +package sdf:df; + + +interface test-df-guest { + use lazy.{ df-value }; + + init-df: func(df: df-value); + test-count: func() -> u64; + test-select: func() -> u64; + test-row: func() -> u64; + test-sort: func() -> u64; + test-sql: func() -> u64; + // test-row-resource: func() -> u64; +} + + +world test-df-world { + import lazy; + export test-df-guest; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/document-state/document.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/document-state/document.wit new file mode 100644 index 00000000..d8d0da64 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/document-state/document.wit @@ -0,0 +1,18 @@ +package sdf:document-state; + +interface document { + + // holds document type + resource document-value { + get: func() -> list; + set: func(val: list); + } + + resource list-document { + get: func() -> list>>; + } +} + +world document-world { + import document; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/document-state/test.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/document-state/test.wit new file mode 100644 index 00000000..b230f187 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/document-state/test.wit @@ -0,0 +1,14 @@ +package sdf:document-state; + +interface test-guest { + use document.{ document-value }; + + // initialize row resource + init-document: func(doc: document-value) ; + run: func(); + +} + +world test-world { + export test-guest; +} diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/deps/arrow/arrow.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/deps/arrow/arrow.wit new file mode 100644 index 00000000..f8aeeb2a --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/deps/arrow/arrow.wit @@ -0,0 +1,151 @@ +package sdf:arrow; + +interface types { + + // arrow types + variant dtype { + %bool, + %i32, + %i64, + %float32, + %float64, + %string, + %timestamp, + %u8, + %u16, + %u32, + %u64, + %i8, + %i16, + } + + variant dvalue { + %bool(bool), + %i32(s32), + %i64(s64), + %float32(f32), + %float64(f64), + %string(string), + %timestamp(u64), + %u8(u8), + %u16(u16), + %u32(u32), + %u64(u64), + %i8(s8), + %i16(s16), + } +} + +// pass arrow data thru wasm boundary +interface wasm-io { + + use types.{ dtype }; + + record view { + offset: u32, + prefix: u32, + length: u32, + buffer-idx: u32, + } + + record utf8-view-array { + views: list, + buffers: list>, + len: u64, + bitmap: option> + } + + record bool-array { + values: tuple, u64>, + len: u64, + bitmap: option> + } + + record %u8-array { + values: list, + len: u64, + bitmap: option> + } + + record %u16-array { + values: list, + len: u64, + bitmap: option> + } + + record %u32-array { + values: list, + len: u64, + bitmap: option> + } + + record %u64-array { + values: list, + len: u64, + bitmap: option> + } + + record i8-array { + values: list, + len: u64, + bitmap: option> + } + + record i16-array { + values: list, + len: u64, + bitmap: option> + } + + record i32-array { + values: list, + len: u64, + bitmap: option> + } + + record i64-array { + values: list, + len: u64, + bitmap: option> + } + + record f32-array { + values: list, + len: u64, + bitmap: option> + } + + record f64-array { + values: list, + len: u64, + bitmap: option> + } + + // list of array chunks + variant array { + utf8(utf8-view-array), + i32(i32-array), + i64(i64-array), + %u8(%u8-array), + %f32(f32-array), + %f64(f64-array), + %bool(%bool-array), + i8(i8-array), + i16(i16-array), + %u16(%u16-array), + %u32(%u32-array), + %u64(%u64-array), + } + + type chunks = list; + + record column { + name: string, + chunks: chunks, + dtype: dtype + } + + record data-frame { + columns: list + } +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/row.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/row.wit new file mode 100644 index 00000000..31e44d10 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/row.wit @@ -0,0 +1,30 @@ +package sdf:row-state; + +interface types { + use sdf:arrow/types.{ dtype, dvalue }; +} + +// row API +interface row { + + use types.{ dtype, dvalue }; + + // similar to duckdb-value + // get and set row value + resource row-value { + + schema: func() -> list>; + + // return values + get: func() -> list>; + + // set values. return error if value is not compatible with existing value + set: func(val: list>) -> result<_,string>; + } + +} + + +world row-world { + import row; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/test.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/test.wit new file mode 100644 index 00000000..36e15ab7 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/row-state/test.wit @@ -0,0 +1,14 @@ +package sdf:row-state; + +interface test-guest { + use row.{ row-value }; + + // initialize row resource + init-row: func(row: row-value) ; + run: func(); + +} + +world test-world { + export test-guest; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/value-state/test.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/value-state/test.wit new file mode 100644 index 00000000..a197a897 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/value-state/test.wit @@ -0,0 +1,13 @@ +package sdf:value-state; + +// guest interface +interface test-guest { + use values.{ value32 }; + + // initialize state + init-state: func(count: value32) ; +} + +world test-world { + export test-guest; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/value-state/value.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/value-state/value.wit new file mode 100644 index 00000000..e56a8547 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/deps/value-state/value.wit @@ -0,0 +1,20 @@ +package sdf:value-state; + +// simple primitive resource value +interface values { + + // holds 32 value + resource value32 { + get: func() -> s32; + set: func(val: s32); + increment: func(val: s32) -> s32; + } + + resource list32 { + get: func() -> list>; + } +} + +world value-world { + import values; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/openai-types/types.wit b/packages/openai/rust/.sdf/.wit/deps/openai-types/types.wit new file mode 100644 index 00000000..89976bb6 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/openai-types/types.wit @@ -0,0 +1,41 @@ +// CODE GENERATED BY sdf +// DO NOT EDIT + +package example:openai-types; + +interface types { + type bytes = list; + + record choice { + finish-reason: string, + index: u64, + message: message, + } + type choice-list = list; + record message { + content: string, + role: string, + } + type messages = list; + record openai-request { + messages: messages, + model: string, + } + record openai-response { + choices: choice-list, + created: u64, + id: string, + model: string, + object: string, + usage: usage, + } + record usage { + completion-tokens: u64, + prompt-tokens: u64, + total-tokens: u64, + } +} + +world openai-types { + export types; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/row-state/deps/arrow/arrow.wit b/packages/openai/rust/.sdf/.wit/deps/row-state/deps/arrow/arrow.wit new file mode 100644 index 00000000..f8aeeb2a --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/row-state/deps/arrow/arrow.wit @@ -0,0 +1,151 @@ +package sdf:arrow; + +interface types { + + // arrow types + variant dtype { + %bool, + %i32, + %i64, + %float32, + %float64, + %string, + %timestamp, + %u8, + %u16, + %u32, + %u64, + %i8, + %i16, + } + + variant dvalue { + %bool(bool), + %i32(s32), + %i64(s64), + %float32(f32), + %float64(f64), + %string(string), + %timestamp(u64), + %u8(u8), + %u16(u16), + %u32(u32), + %u64(u64), + %i8(s8), + %i16(s16), + } +} + +// pass arrow data thru wasm boundary +interface wasm-io { + + use types.{ dtype }; + + record view { + offset: u32, + prefix: u32, + length: u32, + buffer-idx: u32, + } + + record utf8-view-array { + views: list, + buffers: list>, + len: u64, + bitmap: option> + } + + record bool-array { + values: tuple, u64>, + len: u64, + bitmap: option> + } + + record %u8-array { + values: list, + len: u64, + bitmap: option> + } + + record %u16-array { + values: list, + len: u64, + bitmap: option> + } + + record %u32-array { + values: list, + len: u64, + bitmap: option> + } + + record %u64-array { + values: list, + len: u64, + bitmap: option> + } + + record i8-array { + values: list, + len: u64, + bitmap: option> + } + + record i16-array { + values: list, + len: u64, + bitmap: option> + } + + record i32-array { + values: list, + len: u64, + bitmap: option> + } + + record i64-array { + values: list, + len: u64, + bitmap: option> + } + + record f32-array { + values: list, + len: u64, + bitmap: option> + } + + record f64-array { + values: list, + len: u64, + bitmap: option> + } + + // list of array chunks + variant array { + utf8(utf8-view-array), + i32(i32-array), + i64(i64-array), + %u8(%u8-array), + %f32(f32-array), + %f64(f64-array), + %bool(%bool-array), + i8(i8-array), + i16(i16-array), + %u16(%u16-array), + %u32(%u32-array), + %u64(%u64-array), + } + + type chunks = list; + + record column { + name: string, + chunks: chunks, + dtype: dtype + } + + record data-frame { + columns: list + } +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/row-state/row.wit b/packages/openai/rust/.sdf/.wit/deps/row-state/row.wit new file mode 100644 index 00000000..31e44d10 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/row-state/row.wit @@ -0,0 +1,30 @@ +package sdf:row-state; + +interface types { + use sdf:arrow/types.{ dtype, dvalue }; +} + +// row API +interface row { + + use types.{ dtype, dvalue }; + + // similar to duckdb-value + // get and set row value + resource row-value { + + schema: func() -> list>; + + // return values + get: func() -> list>; + + // set values. return error if value is not compatible with existing value + set: func(val: list>) -> result<_,string>; + } + +} + + +world row-world { + import row; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/row-state/test.wit b/packages/openai/rust/.sdf/.wit/deps/row-state/test.wit new file mode 100644 index 00000000..36e15ab7 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/row-state/test.wit @@ -0,0 +1,14 @@ +package sdf:row-state; + +interface test-guest { + use row.{ row-value }; + + // initialize row resource + init-row: func(row: row-value) ; + run: func(); + +} + +world test-world { + export test-guest; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/value-state/test.wit b/packages/openai/rust/.sdf/.wit/deps/value-state/test.wit new file mode 100644 index 00000000..a197a897 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/value-state/test.wit @@ -0,0 +1,13 @@ +package sdf:value-state; + +// guest interface +interface test-guest { + use values.{ value32 }; + + // initialize state + init-state: func(count: value32) ; +} + +world test-world { + export test-guest; +} \ No newline at end of file diff --git a/packages/openai/rust/.sdf/.wit/deps/value-state/value.wit b/packages/openai/rust/.sdf/.wit/deps/value-state/value.wit new file mode 100644 index 00000000..e56a8547 --- /dev/null +++ b/packages/openai/rust/.sdf/.wit/deps/value-state/value.wit @@ -0,0 +1,20 @@ +package sdf:value-state; + +// simple primitive resource value +interface values { + + // holds 32 value + resource value32 { + get: func() -> s32; + set: func(val: s32); + increment: func(val: s32) -> s32; + } + + resource list32 { + get: func() -> list>; + } +} + +world value-world { + import values; +} \ No newline at end of file diff --git a/packages/openai/rust/openai/.wit/chat.wit b/packages/openai/rust/openai/.wit/chat.wit new file mode 100644 index 00000000..935c9405 --- /dev/null +++ b/packages/openai/rust/openai/.wit/chat.wit @@ -0,0 +1,13 @@ +package example:openai; + +interface chat-service { + use example:openai-types/types.{ openai-request }; + use example:openai-types/types.{ openai-response }; + chat: func(request: openai-request,) -> result; +} + +world chat-world { + export chat-service; + + import example:openai-types/types; +} \ No newline at end of file diff --git a/packages/openai/rust/openai/.wit/deps b/packages/openai/rust/openai/.wit/deps new file mode 120000 index 00000000..2d30f365 --- /dev/null +++ b/packages/openai/rust/openai/.wit/deps @@ -0,0 +1 @@ +../../.sdf/.wit/deps \ No newline at end of file diff --git a/packages/openai/rust/openai/.wit/global.wit b/packages/openai/rust/openai/.wit/global.wit new file mode 100644 index 00000000..41300a4e --- /dev/null +++ b/packages/openai/rust/openai/.wit/global.wit @@ -0,0 +1,9 @@ +// CODE GENERATED BY sdf +// DO NOT EDIT +package example:openai; + +world default-world { + export chat-service; + + import example:openai-types/types; +} \ No newline at end of file diff --git a/packages/openai/rust/openai/Cargo.lock b/packages/openai/rust/openai/Cargo.lock new file mode 100644 index 00000000..456b0113 --- /dev/null +++ b/packages/openai/rust/openai/Cargo.lock @@ -0,0 +1,975 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_builder" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" +dependencies = [ + "derive_builder_core", + "syn", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.2", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.166" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "openai" +version = "0.0.0" +dependencies = [ + "anyhow", + "sdfg", + "serde", + "serde_json", + "sjdiff", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "prettyplease" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "sdf-common" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5092c7ce9c8db82b2caaa8d4135c76fe633882d508c88b7f7ba83f5ca04101e3" +dependencies = [ + "anyhow", + "convert_case", + "tracing", +] + +[[package]] +name = "sdf-macros" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f6b41c8c7e1ff14178af0b1009d2e48b57e0751104d9c50a49189f98c1c2ac0" +dependencies = [ + "proc-macro2", + "quote", + "sdf-common", + "sdf-parser-package", + "serde", + "serde_yaml", + "syn", +] + +[[package]] +name = "sdf-parser-core" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a4f7d1424dff240ac5d2e761570eb8edffcfdadca67a9d978306375b57d68c9" +dependencies = [ + "anyhow", + "cfg-if", + "convert_case", + "humantime", + "sdf-common", + "serde", + "serde_with", + "serde_yaml", +] + +[[package]] +name = "sdf-parser-package" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc20ac1636a90bff502a778ca2f0d79c13d1975e004e6ab2a440c1f20feafff" +dependencies = [ + "anyhow", + "cfg-if", + "convert_case", + "humantime", + "sdf-common", + "sdf-parser-core", + "serde", + "serde_with", + "serde_yaml", +] + +[[package]] +name = "sdf-row-guest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab35ba2ea70bb1cd5d4c5d6cca360dc4b14c7957fabe87364f20f28562d6e8b" +dependencies = [ + "anyhow", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "sdfg" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c2b73cf12bb50afd0193f86b0ae13254915e164ea4f011f49364c498dcf2c6a" +dependencies = [ + "sdf-macros", + "sdf-row-guest", + "serde", + "wit-bindgen", +] + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.215" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" +dependencies = [ + "base64", + "chrono", + "hex", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "sjdiff" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa1609b54db569b71a097fb4031d7dc9bce25ad1b08b5525f7571b52764f6a13" +dependencies = [ + "approx", + "chrono", + "derive_builder", + "serde", + "serde_json", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spdx" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bae30cc7bfe3656d60ee99bf6836f472b0c53dddcbf335e253329abb16e535a2" +dependencies = [ + "smallvec", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "wasm-encoder" +version = "0.220.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebf48234b389415b226a4daef6562933d38c7b28a8b8f64c5c4130dad1561ab7" +dependencies = [ + "leb128", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.220.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f3e5f5920c5abfc45573c89b07b38efdaae1515ef86f83dad12d60e50ecd62b" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.220.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e246c2772ce3ebc83f89a2d4487ac5794cad6c309b2071818a88c7db7c36d87b" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "indexmap", + "semver", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c966692b6d8c4bb3c1aee3313e0930f44457a5763cfffb666f814506124e4691" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19857cff2a480fece56ea43f9199322ee5014688a3539ebf8d29ae62d75a3a1f" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "605d5562e971a823cf5a550a9d69cb7144e9b4969a810043127175517a4e1865" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d894e599c161d71acb6a78e8ec8a609a09c2bb227de50829f5afbd03b844a69" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a723cf943bba3bf34f437eb101e5a78180971e25dfb0085d80dbe4e73afb2854" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.220.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ccedf54cc65f287da268d64d2bf4f7530d2cfb2296ffbe3ad5f65567e4cf53" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.220.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b7117ce3adc0b4354b46dc1cf3190b00b333e65243d244c613ffcc58bdec84d" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/packages/openai/rust/openai/Cargo.toml b/packages/openai/rust/openai/Cargo.toml new file mode 100644 index 00000000..66a2b932 --- /dev/null +++ b/packages/openai/rust/openai/Cargo.toml @@ -0,0 +1,43 @@ +[package] +name = "openai" +version = "0.0.0" +edition = "2021" +description = "" + +[lib] +crate-type = ["cdylib"] + +[profile.wasm-debug] +inherits = "dev" +overflow-checks = false +strip = true +panic = "abort" + +[profile.wasm-release] +inherits = "release" +overflow-checks = false +strip = true +opt-level = 'z' +codegen-units = 1 +panic = "abort" + +[profile.wasm-optimized] +inherits = "release" +overflow-checks = false +strip = true +opt-level = 3 +codegen-units = 1 +panic = "abort" + + + +[dependencies] +## GENERATED DEPENDENCIES +anyhow = "1" +serde = { version = "1", features = ["std", "derive"]} +sdfg = { version = "0.8.1" , features=[ "row"] } +## END OF GENERATED DEPENDENCIES + +[dev-dependencies] +sjdiff = "0.0.5" +serde_json = "1.0" \ No newline at end of file diff --git a/packages/openai/rust/openai/README.md b/packages/openai/rust/openai/README.md new file mode 100644 index 00000000..e46a01a4 --- /dev/null +++ b/packages/openai/rust/openai/README.md @@ -0,0 +1 @@ +# openai \ No newline at end of file diff --git a/packages/openai/rust/openai/src/chat.rs b/packages/openai/rust/openai/src/chat.rs new file mode 100644 index 00000000..913124ff --- /dev/null +++ b/packages/openai/rust/openai/src/chat.rs @@ -0,0 +1,11 @@ +use anyhow::Result; +use sdfg::sdf; +use crate::bindings::example::openai_types::types::OpenaiRequest; +use crate::bindings::example::openai_types::types::OpenaiResponse; +#[allow(unused_imports)] +use crate::bindings::example::openai_types::types::*; +#[sdf(fn_name = "chat")] +pub(crate) fn chat(_request: OpenaiRequest) -> Result { + println!("chat called - not implemented!"); + Err(anyhow::anyhow!("chat is not implemented")) +} diff --git a/packages/openai/rust/openai/src/lib.rs b/packages/openai/rust/openai/src/lib.rs new file mode 100644 index 00000000..cde86e09 --- /dev/null +++ b/packages/openai/rust/openai/src/lib.rs @@ -0,0 +1,4 @@ +sdfg::sdf_package!({ path : "../../sdf-package.yaml", }); + +#[cfg(test)] +mod test; \ No newline at end of file diff --git a/packages/openai/rust/openai/src/test.rs b/packages/openai/rust/openai/src/test.rs new file mode 100644 index 00000000..c9fae8ab --- /dev/null +++ b/packages/openai/rust/openai/src/test.rs @@ -0,0 +1,98 @@ +use std::fs::read_to_string; + +use serde_json::Value; + +const EXAMPLE_REQUEST: &str = r#"{ + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "user", + "content": "tell me a story" + } + ] +}"#; + + +/// test good serialization +#[test] +fn serialize_good() { + + use crate::bindings::example::openai_types::types::{OpenaiRequest,Message}; + + + let req = OpenaiRequest { + model: "gpt-3.5-turbo".to_string(), + messages: vec![ + Message { + role: "user".to_string(), + content: "tell me a story".to_string() + } + ] + }; + + let generated: Value = serde_json::to_value(&req).unwrap(); + + // this should be the same as the original + let original: Value = serde_json::from_str(EXAMPLE_REQUEST).unwrap(); + let diff = sjdiff::DiffBuilder::default() + .source(generated) + .target(original) + .build() + .unwrap(); + let diff = diff.compare(); + assert!(diff.is_none()); + + +} + +/// test bad serialization and print diff +#[test] +fn sieralize_bad() { + + use crate::bindings::example::openai_types::types::{OpenaiRequest,Message}; + + + let req = OpenaiRequest { + model: "gpt-3.5-turbo".to_string(), + messages: vec![ + Message { + role: "user2".to_string(), + content: "tell me a story".to_string() + } + ] + }; + + let generated: Value = serde_json::to_value(&req).unwrap(); + + // this should be the same as the original + let original: Value = serde_json::from_str(EXAMPLE_REQUEST).unwrap(); + let diff = sjdiff::DiffBuilder::default() + .source(generated) + .target(original) + .build() + .unwrap(); + let diff = diff.compare(); + assert!(diff.is_some()); + + // print diff + serde_json::to_writer_pretty(std::io::stdout(), &diff).unwrap(); + +} + + + + +/// test good deserialization +#[test] +fn deserialize_good() { + + use crate::bindings::example::openai_types::types::{OpenaiResponse}; + + let original_json = read_to_string("../../response.json").unwrap(); + let resp: OpenaiResponse = serde_json::from_str(&original_json).unwrap(); + + assert_eq!(resp.id,"12"); + assert_eq!(resp.model,"gpt-4o-2024-08-06"); + assert_eq!(resp.choices.len(),1); + +} \ No newline at end of file diff --git a/packages/openai/sdf-package.yaml b/packages/openai/sdf-package.yaml new file mode 100644 index 00000000..e7e69e76 --- /dev/null +++ b/packages/openai/sdf-package.yaml @@ -0,0 +1,77 @@ +apiVersion: 0.5.0 + +meta: + name: openai + version: 0.1.0 + namespace: example + +types: + openai-request: + type: object + properties: + model: + type: string + messages: + type: list + type-name: messages + items: + type: message + + message: + type: object + properties: + role: + type: string + content: + type: string + + openai-response: + type: object + properties: + id: + type: string + object: + type: string + created: + type: u64 + model: + type: string + choices: + type: list + type-name: choice-list + items: + type: choice + usage: + type: usage + + + choice: + type: object + properties: + index: + type: u64 + message: + type: message + finish-reason: + type: string + + usage: + type: object + properties: + prompt_tokens: + type: u64 + completion_tokens: + type: u64 + total_tokens: + type: u64 + + +functions: + + chat: + operator: map + inputs: + - name: request + type: openai-request + output: + type: openai-response