Skip to main content

gproxy_protocol/adapt/generate/chat_gemini/
synthesis.rs

1use super::*;
2
3impl ChatViaGemini {
4    /// Prepare a buffered upstream result for later native stream synthesis,
5    /// retaining the original client stream flag and all declared controls.
6    pub async fn prepare_for_stream_synthesis<S: crate::capability::StateStore>(
7        input: h::GenerateContentRequestBody,
8        endpoint: Endpoint,
9        identities: GenerationIdentity,
10        state: &super::super::GenerationStateAccess<'_, S>,
11        function_names: &std::collections::BTreeMap<String, String>,
12    ) -> Result<Self, TransformError> {
13        let original = input.into_declared();
14        let mut buffered = original.clone();
15        buffered.stream = Some(Some(false));
16        let mut prepared =
17            Self::prepare_with_state(buffered, endpoint, identities, state, function_names).await?;
18        prepared.original_request = original;
19        Ok(prepared)
20    }
21    /// Prepare a buffered upstream result for later native stream synthesis,
22    /// retaining the original client stream flag and all declared controls.
23    pub async fn prepare_for_stream_synthesis_with_capabilities<
24        S: crate::capability::StateStore,
25        R: crate::capability::ResourceAccess,
26    >(
27        input: h::GenerateContentRequestBody,
28        endpoint: Endpoint,
29        identities: GenerationIdentity,
30        state: &super::super::GenerationStateAccess<'_, S>,
31        resources: &super::super::GenerationResources<'_, R>,
32        function_names: &std::collections::BTreeMap<String, String>,
33    ) -> Result<Self, TransformError> {
34        let original = input.into_declared();
35        let mut buffered = original.clone();
36        buffered.stream = Some(Some(false));
37        let mut prepared = Self::prepare_with_capabilities(
38            buffered,
39            endpoint,
40            identities,
41            state,
42            resources,
43            function_names,
44        )
45        .await?;
46        prepared.original_request = original;
47        Ok(prepared)
48    }
49}
50
51impl GeminiViaChat {
52    /// Prepare a buffered upstream result for later native stream synthesis,
53    /// retaining the original client stream flag and all declared controls.
54    pub async fn prepare_for_stream_synthesis<S: crate::capability::StateStore>(
55        input: g::GenerateContentRequestBody,
56        endpoint: Endpoint,
57        identities: GenerationIdentity,
58        state: &super::super::GenerationStateAccess<'_, S>,
59    ) -> Result<Self, TransformError> {
60        let original = input.into_declared();
61        let buffered = original.clone();
62        let mut prepared = Self::prepare_with_state(buffered, endpoint, identities, state).await?;
63        prepared.original_request = original;
64        prepared.target_request.stream = Some(Some(false));
65        Ok(prepared)
66    }
67    /// Prepare a buffered upstream result for later native stream synthesis,
68    /// retaining the original client stream flag and all declared controls.
69    pub async fn prepare_for_stream_synthesis_with_capabilities<
70        S: crate::capability::StateStore,
71        R: crate::capability::ResourceAccess,
72    >(
73        input: g::GenerateContentRequestBody,
74        endpoint: Endpoint,
75        identities: GenerationIdentity,
76        state: &super::super::GenerationStateAccess<'_, S>,
77        resources: &super::super::GenerationResources<'_, R>,
78    ) -> Result<Self, TransformError> {
79        let original = input.into_declared();
80        let buffered = original.clone();
81        let mut prepared =
82            Self::prepare_with_capabilities(buffered, endpoint, identities, state, resources)
83                .await?;
84        prepared.original_request = original;
85        prepared.target_request.stream = Some(Some(false));
86        Ok(prepared)
87    }
88}