theRealNG commited on
Commit
923909d
·
1 Parent(s): edbc347

lib(supabase_client): add support to post to supabase

Browse files
.env.example CHANGED
@@ -1,11 +1,16 @@
1
  OPENAI_API_KEY=""
2
- OPENAI_MODEL="gpt-3.5-turbo"
3
  GOOGLE_API_KEY=""
4
 
5
  LANGCHAIN_TRACING_V2=true
6
  LANGCHAIN_API_KEY=""
7
  LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
8
- LANGCHAIN_PROJECT="growthy-agents"
9
 
10
- TAVILY_API_KEY=""
11
  ENV="local"
 
 
 
 
 
 
 
1
  OPENAI_API_KEY=""
2
+ OPENAI_MODEL="gpt-4o-mini"
3
  GOOGLE_API_KEY=""
4
 
5
  LANGCHAIN_TRACING_V2=true
6
  LANGCHAIN_API_KEY=""
7
  LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
8
+ LANGCHAIN_PROJECT="customer_agent"
9
 
 
10
  ENV="local"
11
+
12
+ SUPABASE_URL_STAGING=""
13
+ SUPABASE_KEY_STAGING=""
14
+
15
+ SUPABASE_URL_PROD=""
16
+ SUPABASE_KEY_PROD=""
endpoints.py CHANGED
@@ -15,13 +15,23 @@ from fastapi.middleware.cors import CORSMiddleware
15
  from pydantic import UUID4
16
  from tempenv import TemporaryEnvironment
17
  from typing import List
 
18
  import uvicorn
19
 
20
 
21
- LANGSMITH_STAGING_PROJECT = "customer_agent"
22
- LANGSMITH_PROD_PROJECT = "growthy-agents"
23
- LANGSMITH_STAGING_MODEL = "gpt-4o-mini"
24
- LANGSMITH_PROD_MODEL = "gpt-4o"
 
 
 
 
 
 
 
 
 
25
 
26
  description = """
27
  API helps you do awesome stuff. 🚀
@@ -73,7 +83,7 @@ async def capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
73
 
74
  @app.post("/staging/til_feedback", tags=["til_feedback", "staging"])
75
  async def staging_til_feedback_kickoff(content: List[str]) -> TilFeedbackResponse:
76
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
77
  separator = "\n* "
78
  content[0] = "* " + content[0]
79
  inputs = {"content": separator.join(content)}
@@ -83,7 +93,7 @@ async def staging_til_feedback_kickoff(content: List[str]) -> TilFeedbackRespons
83
 
84
  @app.post("/staging/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
85
  async def staging_capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
86
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
87
  post_feedback(run_id=run_id, feedback=feedback)
88
  return "ok"
89
 
@@ -96,12 +106,12 @@ def til_v2_analyze_logic(content) -> TilV2FeedbackResponse:
96
 
97
  @app.post("/v2/til_feedback", tags=["til_feedback"])
98
  async def til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
99
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
100
  return til_v2_analyze_logic(content)
101
 
102
  @app.post("/v2/til_feedback/{run_id}/feedback", tags=["til_feedback"])
103
  async def capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
104
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
105
  feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
106
  return "ok"
107
 
@@ -109,20 +119,20 @@ async def capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
109
 
110
  @app.post("/staging/v2/til_feedback", tags=["til_feedback", "staging"])
111
  async def staging_til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
112
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
113
  return til_v2_analyze_logic(content)
114
 
115
 
116
  @app.post("/staging/v2/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
117
  async def staging_capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
118
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_MODEL, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
119
  feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
120
  return "ok"
121
 
122
 
123
  @app.post("/v2/til_rewrite", tags=["til_readability"])
124
  async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
125
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
126
  inputs = CreateTilInputs(content)
127
  result = RewriteTilV2().kickoff(inputs)
128
  return result
@@ -130,14 +140,14 @@ async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
130
 
131
  @app.post("/v2/til_rewrite/{run_id}/feedback", tags=["til_readability"])
132
  async def capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
133
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
134
  feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
135
  return "ok"
136
 
137
 
138
  @app.post("/staging/v2/til_rewrite", tags=["til_readability", "staging"])
139
  async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
140
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
141
  inputs = CreateTilInputs(content)
142
  result = RewriteTilV2().kickoff(inputs)
143
  return result
@@ -145,14 +155,14 @@ async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilRespon
145
 
146
  @app.post("/staging/v2/til_rewrite/{run_id}/feedback", tags=["til_readability", "staging"])
147
  async def staging_capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
148
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
149
  feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
150
  return "ok"
151
 
152
 
153
  @app.post("/v2/til_headlines", tags=["til_headlines"])
154
  async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
155
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
156
  inputs = CreateTilInputs(content)
157
  result = SuggestHeadlinesV2().kickoff(inputs)
158
  return result
@@ -160,14 +170,14 @@ async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesRespon
160
 
161
  @app.post("/v2/til_headlines/{run_id}/feedback", tags=["til_headlines"])
162
  async def capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
163
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
164
  feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
165
  return "ok"
166
 
167
 
168
  @app.post("/staging/v2/til_headlines", tags=["til_headlines", "staging"])
169
  async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
170
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
171
  inputs = CreateTilInputs(content)
172
  result = SuggestHeadlinesV2().kickoff(inputs)
173
  return result
@@ -175,7 +185,7 @@ async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlin
175
 
176
  @app.post("/staging/v2/til_headlines/{run_id}/feedback", tags=["til_headlines", "staging"])
177
  async def staging_capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
178
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_MODEL, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
179
  feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
180
  return "ok"
181
 
@@ -203,25 +213,25 @@ def course_learn_suggest_expectations_feedback_logic(run_id: UUID4, feedback: Fe
203
 
204
  @app.post("/course_learn/suggest_expectations", tags=["course_learn"])
205
  async def course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> SuggestExpectationsResponse:
206
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
207
  return course_learn_suggest_expectations_logic(inputs)
208
 
209
 
210
  @app.post("/staging/course_learn/suggest_expectations", tags=["course_learn", "staging"])
211
  async def staging_course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> SuggestExpectationsResponse:
212
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
213
  return course_learn_suggest_expectations_logic(inputs)
214
 
215
 
216
  @app.post("/course_learn/suggest_expectations/{run_id}/feedback", tags=["course_learn"])
217
  async def capture_suggest_expectations_feedback(run_id: UUID4, feedback: Feedback) -> str:
218
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
219
  return course_learn_suggest_expectations_feedback_logic(run_id, feedback)
220
 
221
 
222
  @app.post("/staging/course_learn/suggest_expectations/{run_id}/feedback", tags=["course_learn", "staging"])
223
  async def staging_capture_suggest_expectations_feedback(run_id: UUID4, feedback: Feedback) -> str:
224
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
225
  return course_learn_suggest_expectations_feedback_logic(run_id, feedback)
226
 
227
 
@@ -237,13 +247,13 @@ def course_learn_expectation_revision_logic(inputs: ExpectationRevisionInputs) -
237
 
238
  @app.post("/course_learn/expectation_revision", tags=["course_learn"])
239
  async def course_learn_expectation_revision(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
240
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
241
  return course_learn_expectation_revision_logic(inputs)
242
 
243
 
244
  @app.post("/staging/course_learn/expectation_revision", tags=["course_learn", "staging"])
245
  async def staging_course_learn_expectation_revision(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
246
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
247
  return course_learn_expectation_revision_logic(inputs)
248
 
249
 
@@ -256,13 +266,13 @@ def capture_expectation_revision_feedback_logic(run_id: UUID4, feedback: Feedbac
256
 
257
  @app.post("/course_learn/expectation_revision/{run_id}/feedback", tags=["course_learn"])
258
  async def capture_expectation_revision_feedback(run_id: UUID4, feedback: Feedback) -> str:
259
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
260
  return capture_expectation_revision_feedback_logic(run_id, feedback)
261
 
262
 
263
  @app.post("/staging/course_learn/expectation_revision/{run_id}/feedback", tags=["course_learn", "staging"])
264
  async def staging_capture_expectation_revision_feedback(run_id: UUID4, feedback: Feedback) -> str:
265
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
266
  return capture_expectation_revision_feedback_logic(run_id, feedback)
267
 
268
 
@@ -279,13 +289,13 @@ def course_learn_suggest_check_question_logic(inputs: SuggestCheckQuestionInputs
279
 
280
  @app.post("/course_learn/suggest_check_question", tags=["course_learn"])
281
  async def course_learn_suggest_check_question(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
282
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
283
  return course_learn_suggest_check_question_logic(inputs)
284
 
285
 
286
  @app.post("/staging/course_learn/suggest_check_question", tags=["course_learn", "staging"])
287
  async def staging_course_learn_suggest_check_question(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
288
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
289
  return course_learn_suggest_check_question_logic(inputs)
290
 
291
 
@@ -298,26 +308,26 @@ def course_learn_suggest_check_question_feedback_logic(run_id: UUID4, feedback:
298
 
299
  @app.post("/course_learn/suggest_check_question/{run_id}/feedback", tags=["course_learn"])
300
  async def course_learn_suggest_check_question_feedback(run_id: UUID4, feedback: Feedback) -> str:
301
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
302
  return course_learn_suggest_check_question_feedback_logic(run_id, feedback)
303
 
304
 
305
  @app.post("/staging/course_learn/suggest_check_question/{run_id}/feedback", tags=["course_learn", "staging"])
306
  async def staging_course_learn_suggest_check_question_feedback(run_id: UUID4, feedback: Feedback) -> str:
307
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
308
  return course_learn_suggest_check_question_feedback_logic(run_id, feedback)
309
 
310
 
311
  @app.post("/llm_feedback/{run_id}/feedback", tags=["llm_feedback"])
312
  async def capture_llm_feedback(run_id: UUID4, feedback: Feedback) -> str:
313
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
314
  post_feedback(run_id=run_id, feedback=feedback)
315
  return "ok"
316
 
317
 
318
  @app.post("/staging/llm_feedback/{run_id}/feedback", tags=["llm_feedback", "staging"])
319
  async def staging_capture_llm_feedback(run_id: UUID4, feedback: Feedback) -> str:
320
- with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
321
  post_feedback(run_id=run_id, feedback=feedback)
322
  return "ok"
323
 
 
15
  from pydantic import UUID4
16
  from tempenv import TemporaryEnvironment
17
  from typing import List
18
+ import os
19
  import uvicorn
20
 
21
 
22
+ STAGING_ENV_CONFIG = {
23
+ "LANGCHAIN_PROJECT": "customer_agent",
24
+ "OPENAI_MODEL": "gpt-4o-mini",
25
+ "SUPABASE_URL": os.environ["SUPABASE_URL_STAGING"],
26
+ "SUPABASE_KEY": os.environ["SUPABASE_KEY_STAGING"]
27
+ }
28
+
29
+ PROD_ENV_CONFIG = {
30
+ "LANGCHAIN_PROJECT": "growthy-agents-prod",
31
+ "OPENAI_MODEL": "gpt-4o",
32
+ "SUPABASE_URL": os.environ["SUPABASE_URL_PROD"],
33
+ "SUPABASE_KEY": os.environ["SUPABASE_KEY_PROD"]
34
+ }
35
 
36
  description = """
37
  API helps you do awesome stuff. 🚀
 
83
 
84
  @app.post("/staging/til_feedback", tags=["til_feedback", "staging"])
85
  async def staging_til_feedback_kickoff(content: List[str]) -> TilFeedbackResponse:
86
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
87
  separator = "\n* "
88
  content[0] = "* " + content[0]
89
  inputs = {"content": separator.join(content)}
 
93
 
94
  @app.post("/staging/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
95
  async def staging_capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
96
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
97
  post_feedback(run_id=run_id, feedback=feedback)
98
  return "ok"
99
 
 
106
 
107
  @app.post("/v2/til_feedback", tags=["til_feedback"])
108
  async def til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
109
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
110
  return til_v2_analyze_logic(content)
111
 
112
  @app.post("/v2/til_feedback/{run_id}/feedback", tags=["til_feedback"])
113
  async def capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
114
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
115
  feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
116
  return "ok"
117
 
 
119
 
120
  @app.post("/staging/v2/til_feedback", tags=["til_feedback", "staging"])
121
  async def staging_til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
122
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
123
  return til_v2_analyze_logic(content)
124
 
125
 
126
  @app.post("/staging/v2/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
127
  async def staging_capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
128
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
129
  feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
130
  return "ok"
131
 
132
 
133
  @app.post("/v2/til_rewrite", tags=["til_readability"])
134
  async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
135
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
136
  inputs = CreateTilInputs(content)
137
  result = RewriteTilV2().kickoff(inputs)
138
  return result
 
140
 
141
  @app.post("/v2/til_rewrite/{run_id}/feedback", tags=["til_readability"])
142
  async def capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
143
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
144
  feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
145
  return "ok"
146
 
147
 
148
  @app.post("/staging/v2/til_rewrite", tags=["til_readability", "staging"])
149
  async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
150
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
151
  inputs = CreateTilInputs(content)
152
  result = RewriteTilV2().kickoff(inputs)
153
  return result
 
155
 
156
  @app.post("/staging/v2/til_rewrite/{run_id}/feedback", tags=["til_readability", "staging"])
157
  async def staging_capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
158
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
159
  feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
160
  return "ok"
161
 
162
 
163
  @app.post("/v2/til_headlines", tags=["til_headlines"])
164
  async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
165
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
166
  inputs = CreateTilInputs(content)
167
  result = SuggestHeadlinesV2().kickoff(inputs)
168
  return result
 
170
 
171
  @app.post("/v2/til_headlines/{run_id}/feedback", tags=["til_headlines"])
172
  async def capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
173
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
174
  feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
175
  return "ok"
176
 
177
 
178
  @app.post("/staging/v2/til_headlines", tags=["til_headlines", "staging"])
179
  async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
180
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
181
  inputs = CreateTilInputs(content)
182
  result = SuggestHeadlinesV2().kickoff(inputs)
183
  return result
 
185
 
186
  @app.post("/staging/v2/til_headlines/{run_id}/feedback", tags=["til_headlines", "staging"])
187
  async def staging_capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
188
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
189
  feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
190
  return "ok"
191
 
 
213
 
214
  @app.post("/course_learn/suggest_expectations", tags=["course_learn"])
215
  async def course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> SuggestExpectationsResponse:
216
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
217
  return course_learn_suggest_expectations_logic(inputs)
218
 
219
 
220
  @app.post("/staging/course_learn/suggest_expectations", tags=["course_learn", "staging"])
221
  async def staging_course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> SuggestExpectationsResponse:
222
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
223
  return course_learn_suggest_expectations_logic(inputs)
224
 
225
 
226
  @app.post("/course_learn/suggest_expectations/{run_id}/feedback", tags=["course_learn"])
227
  async def capture_suggest_expectations_feedback(run_id: UUID4, feedback: Feedback) -> str:
228
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
229
  return course_learn_suggest_expectations_feedback_logic(run_id, feedback)
230
 
231
 
232
  @app.post("/staging/course_learn/suggest_expectations/{run_id}/feedback", tags=["course_learn", "staging"])
233
  async def staging_capture_suggest_expectations_feedback(run_id: UUID4, feedback: Feedback) -> str:
234
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
235
  return course_learn_suggest_expectations_feedback_logic(run_id, feedback)
236
 
237
 
 
247
 
248
  @app.post("/course_learn/expectation_revision", tags=["course_learn"])
249
  async def course_learn_expectation_revision(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
250
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
251
  return course_learn_expectation_revision_logic(inputs)
252
 
253
 
254
  @app.post("/staging/course_learn/expectation_revision", tags=["course_learn", "staging"])
255
  async def staging_course_learn_expectation_revision(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
256
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
257
  return course_learn_expectation_revision_logic(inputs)
258
 
259
 
 
266
 
267
  @app.post("/course_learn/expectation_revision/{run_id}/feedback", tags=["course_learn"])
268
  async def capture_expectation_revision_feedback(run_id: UUID4, feedback: Feedback) -> str:
269
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
270
  return capture_expectation_revision_feedback_logic(run_id, feedback)
271
 
272
 
273
  @app.post("/staging/course_learn/expectation_revision/{run_id}/feedback", tags=["course_learn", "staging"])
274
  async def staging_capture_expectation_revision_feedback(run_id: UUID4, feedback: Feedback) -> str:
275
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
276
  return capture_expectation_revision_feedback_logic(run_id, feedback)
277
 
278
 
 
289
 
290
  @app.post("/course_learn/suggest_check_question", tags=["course_learn"])
291
  async def course_learn_suggest_check_question(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
292
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
293
  return course_learn_suggest_check_question_logic(inputs)
294
 
295
 
296
  @app.post("/staging/course_learn/suggest_check_question", tags=["course_learn", "staging"])
297
  async def staging_course_learn_suggest_check_question(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
298
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
299
  return course_learn_suggest_check_question_logic(inputs)
300
 
301
 
 
308
 
309
  @app.post("/course_learn/suggest_check_question/{run_id}/feedback", tags=["course_learn"])
310
  async def course_learn_suggest_check_question_feedback(run_id: UUID4, feedback: Feedback) -> str:
311
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
312
  return course_learn_suggest_check_question_feedback_logic(run_id, feedback)
313
 
314
 
315
  @app.post("/staging/course_learn/suggest_check_question/{run_id}/feedback", tags=["course_learn", "staging"])
316
  async def staging_course_learn_suggest_check_question_feedback(run_id: UUID4, feedback: Feedback) -> str:
317
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
318
  return course_learn_suggest_check_question_feedback_logic(run_id, feedback)
319
 
320
 
321
  @app.post("/llm_feedback/{run_id}/feedback", tags=["llm_feedback"])
322
  async def capture_llm_feedback(run_id: UUID4, feedback: Feedback) -> str:
323
+ with TemporaryEnvironment(PROD_ENV_CONFIG):
324
  post_feedback(run_id=run_id, feedback=feedback)
325
  return "ok"
326
 
327
 
328
  @app.post("/staging/llm_feedback/{run_id}/feedback", tags=["llm_feedback", "staging"])
329
  async def staging_capture_llm_feedback(run_id: UUID4, feedback: Feedback) -> str:
330
+ with TemporaryEnvironment(STAGING_ENV_CONFIG):
331
  post_feedback(run_id=run_id, feedback=feedback)
332
  return "ok"
333
 
lib/supabase_client.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import UUID4
2
+ from supabase import create_client
3
+ import os
4
+
5
+ FEEDBACK_TABLE_NAME = "llm_feedback"
6
+
7
+
8
+ class SupabaseClient:
9
+ def __init__(self):
10
+ url = os.environ.get("SUPABASE_URL")
11
+ key = os.environ.get("SUPABASE_KEY")
12
+ self.client = create_client(url, key)
13
+
14
+ def post_feedback(self, run_id: UUID4, metric_type: str, metric_score: float, sub_workflow: str):
15
+ try:
16
+ response = self.client.table(FEEDBACK_TABLE_NAME).insert({
17
+ "run_id": str(run_id),
18
+ "sub_workflow": sub_workflow,
19
+ "metric_type": metric_type,
20
+ "metric_score": metric_score,
21
+ }).execute()
22
+ print("Response: ", response)
23
+ return response
24
+ except Exception as exception:
25
+ print("Exception: ", exception)
26
+ return exception
requirements.txt CHANGED
@@ -3,6 +3,7 @@ asyncio
3
  crewai
4
  crewai_tools
5
  fastapi
 
6
  fastapi_cors
7
  langchain_community
8
  langchain_google_genai
@@ -19,6 +20,7 @@ semanticscholar
19
  streamlit
20
  streamlit-extras
21
  streamlit_router
 
22
  tavily-python
23
  tempenv
24
  unstructured
 
3
  crewai
4
  crewai_tools
5
  fastapi
6
+ fastapi[standard]
7
  fastapi_cors
8
  langchain_community
9
  langchain_google_genai
 
20
  streamlit
21
  streamlit-extras
22
  streamlit_router
23
+ supabase
24
  tavily-python
25
  tempenv
26
  unstructured
workflows/utils/feedback.py CHANGED
@@ -1,6 +1,7 @@
1
  from pydantic import BaseModel, UUID4
2
  from typing import List, Optional
3
  from langsmith import Client
 
4
 
5
  class Feedback(BaseModel):
6
  metric_type: Optional[str]
@@ -32,12 +33,17 @@ class NewFeedback(BaseModel):
32
  run_id = inputs["run_id"]
33
  sub_workflow = inputs["sub_workflow"]
34
 
35
- # make a call to supabase
36
- self._post_to_supbase()
37
-
38
  self._post_to_langsmith(run_id)
39
 
40
- def _post_to_supbase(self):
 
 
 
 
 
 
 
41
  return
42
 
43
  def _post_to_langsmith(self, run_id: UUID4):
 
1
  from pydantic import BaseModel, UUID4
2
  from typing import List, Optional
3
  from langsmith import Client
4
+ from ..lib.supabase_client import SupabaseClient
5
 
6
  class Feedback(BaseModel):
7
  metric_type: Optional[str]
 
33
  run_id = inputs["run_id"]
34
  sub_workflow = inputs["sub_workflow"]
35
 
36
+ self._post_to_supbase(run_id, sub_workflow)
 
 
37
  self._post_to_langsmith(run_id)
38
 
39
+ def _post_to_supbase(self, run_id: UUID4, sub_worfklow: str):
40
+ client = SupabaseClient()
41
+ client.post_feedback(
42
+ run_id= run_id,
43
+ sub_workflow= sub_worfklow,
44
+ metric_score=self.metric_score,
45
+ metric_type=self.metric_type
46
+ )
47
  return
48
 
49
  def _post_to_langsmith(self, run_id: UUID4):