1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use ;
use crate::;
/// [Azure Execution Provider](https://onnxruntime.ai/docs/execution-providers/Azure-ExecutionProvider.html) enables
/// operators that invoke Azure cloud models.
///
/// The Azure EP enables the use of [`onnxruntime-extensions`](https://github.com/microsoft/onnxruntime-extensions)'
/// [Azure operators](https://github.com/microsoft/onnxruntime-extensions/blob/v0.14.0/docs/custom_ops.md#azure-operators).
///
/// # Example
/// Using an example model generated in Python with:
/// ```python
/// from onnx import *
///
/// azure_model_uri = "https://myname-aoai-test.openai.azure.com/openai/deployments/mydeploy/chat/completions?api-version=2023-05-15"
///
/// auth_token = helper.make_tensor_value_info('auth_token', TensorProto.STRING, [-1])
/// chat = helper.make_tensor_value_info('chat', TensorProto.STRING, [-1])
/// response = helper.make_tensor_value_info('response', TensorProto.STRING, [-1])
///
/// invoker = helper.make_node(
/// 'AzureTextToText',
/// [ 'auth_token', 'chat' ],
/// [ 'response' ],
/// domain='com.microsoft.extensions',
/// name='chat_invoker',
/// model_uri=azure_model_uri
/// )
///
/// graph = helper.make_graph([ invoker ], 'graph', [ auth_token, chat ], [ response ])
/// model = helper.make_model(graph, opset_imports=[helper.make_operatorsetid('com.microsoft.extensions', 1)])
///
/// onnx.save(model, 'azure_chat.onnx')
/// ```
///
/// To use this model in `ort`:
/// ```no_run
/// # use ort::{ep, session::Session, value::Tensor};
/// # fn main() -> ort::Result<()> {
/// let mut session = Session::builder()?
/// // note: session must be initialized with `onnxruntime-extensions`
/// .with_extensions()?
/// .with_execution_providers([ep::Azure::default().build()])?
/// .commit_from_file("azure_chat.onnx")?;
///
/// let auth_token = Tensor::from_string_array(([1], &*vec!["..."]))?;
/// let input = Tensor::from_string_array((
/// [1],
/// &*vec![
/// r#"
/// {
/// "messages": [
/// { "role": "system", "content": "You are a helpful assistant." },
/// { "role": "user", "content": "Does Azure OpenAI support customer managed keys?" },
/// { "role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI." },
/// { "role": "user", "content": "Do other Azure AI services support this too?" }
/// ]
/// }
/// "#,
/// ]
/// ))?;
/// let outputs = session.run(ort::inputs![input])?;
/// let (_, response_json_strings) = &outputs[0].try_extract_strings()?;
/// # Ok(())
/// # }
/// ```
impl_ep!;