File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
articles/ai-services/openai/references Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ description: Learn how to use Azure OpenAI On Your Data Python & REST API.
5
5
manager : nitinme
6
6
ms.service : azure-ai-openai
7
7
ms.topic : conceptual
8
- ms.date : 06/13 /2024
8
+ ms.date : 07/18 /2024
9
9
author : mrbullwinkle
10
10
ms.author : mbullwin
11
11
recommendations : false
@@ -174,6 +174,20 @@ completion = client.chat.completions.create(
174
174
175
175
print (completion.model_dump_json(indent = 2 ))
176
176
177
+ # render the citations
178
+
179
+ content = completion.choices[0 ].message.content
180
+ context = completion.choices[0 ].message.context
181
+ for citation_index, citation in enumerate (context[" citations" ]):
182
+ citation_reference = f " [doc { citation_index + 1 } ] "
183
+ url = " https://example.com/?redirect=" + citation[" url" ] # replace with actual host and encode the URL
184
+ filepath = citation[" filepath" ]
185
+ title = citation[" title" ]
186
+ snippet = citation[" content" ]
187
+ chunk_id = citation[" chunk_id" ]
188
+ replaced_html = f " <a href=' { url} ' title=' { title} \n { snippet} ''>(See from file { filepath} , Part { chunk_id} )</a> "
189
+ content = content.replace(citation_reference, replaced_html)
190
+ print (content)
177
191
```
178
192
179
193
# [ REST] ( #tab/rest )
You can’t perform that action at this time.
0 commit comments