anthropics / anthropic-sdk-python

MIT License
1.31k stars 158 forks source link

How to achieve an effect similar to uploading file attachments on the web page in the API? #129

Closed WSC741606 closed 1 year ago

WSC741606 commented 1 year ago

I now have some plain text files to process, but I found that if I upload attachments on the web page, the response I get is significantly better than the results obtained by using the API. I would like to know if there is any way to make the results of the API look like the results of the web page?

The format of the prompt I send in the API is roughly like this:

{Introduction}
Here is the file, in <File></File>XML tags:
<File>
{document content}
</File>

What I send on the web page is this: "{Introduction}", and then upload the file as an attachment.

My understanding is that there should be a fixed format on the web page to connect the file content and my prompt to get better results. Can I get this splicing format? If you need the text of the {introduction} part or specific text files involved here, please contact me, thank you very much! This problem has bothered me for several days, I am looking forward to your reply :)

rattrayalex commented 1 year ago

Sorry, this functionality isn't available in the API at this time. You can use a tool like pandoc to convert your file to text, and include the text inline in the format you describe.

WSC741606 commented 1 year ago

Sorry, this functionality isn't available in the API at this time. You can use a tool like pandoc to convert your file to text, and include the text inline in the format you describe.

Sorry, my file is in plain text, I just want to find a better way to merge it with my prompt.

rattrayalex commented 1 year ago

Ah, you can just inject the file contents with string templating as you would any other text in that case! Are you seeing any difference in behavior when doing this between the API and the chat UI?

WSC741606 commented 1 year ago

Ah, you can just inject the file contents with string templating as you would any other text in that case! Are you seeing any difference in behavior when doing this between the API and the chat UI?

Very different in these two way. In fact, when I send the file in the template I mentioned above via API, Claude misunderstood what I said in Introduction part. I want to generate DOIs in the format "[actual_doi]", but got the raw return. Same prompt via web UI worded well.

WSC741606 commented 1 year ago

Ah, you can just inject the file contents with string templating as you would any other text in that case! Are you seeing any difference in behavior when doing this between the API and the chat UI?

Very different in these two way. In fact, when I send the file in the template I mentioned above via API, Claude misunderstood what I said in Introduction part. I want to generate DOIs in the format "[actual_doi]", but got the raw return. Same prompt via web UI worded well.

API: DFT calculations have provided valuable atomic-level insights into propane dehydrogenation mechanisms, active sites, and factors impacting catalyst performance that complement experimental findings [actual_doi1, actual_doi2]. For example, DFT predicted Pt3In would show optimal balance between activity and selectivity, which was later validated experimentally [actual_doi3]. Calculations on Pt and PtZn surfaces revealed weaker binding of intermediates explains higher selectivity versus pure Pt [actual_doi4, actual_doi5]. DFT elucidated how promoters like Sn, Cu, and Ga modify electronic properties of metals to tune selectivity [actual_doi6, actual_doi7, actual_doi9]. Computations also shed light on active sites like isolated metal atoms [actual_doi8], metal-support interface sites [actual_doi10], and dual sites that cooperatively activate propane and hydrogen [actual_doi11, actual_doi12].

Web: Density functional theory (DFT) calculations have become an indispensable tool in elucidating the behavior of propane dehydrogenation catalysts and providing atomic-level insights into their activity and mechanisms. DFT allows quantitative determination of reaction energetics, optimization of geometries, identification of intermediates and transition states, and analysis of electronic factors influencing reactivity [10.1021/cs300031d, 10.1021/ja0611745]. When combined with kinetic modeling or experiments, DFT offers a powerful approach for rational catalyst design [10.1038/s41467-018-06174-5, 10.1021/acs.jpcc.9b04991].

This is a piece of example of these two way.

WSC741606 commented 1 year ago

That's why I really want to know how the files are attached to the prompt in the web. You know, in large language models, small changes can have very different results. I suspect it's because of the relevant format specification in the pretrained corpus, so I turn to you.

WSC741606 commented 1 year ago

Not only the difference in the output format, in my task I want Claude to summarize the content entries of the file (listed in JSON format), but many of the results sent from the API will simply enumerate the results, while in the web page The terminal will really summarize and refine like a scientific researcher.

jenan-anthropic commented 1 year ago

@WSC741606 We'll have more recipes for these types of tasks soon!

WSC741606 commented 1 year ago

@WSC741606 We'll have more recipes for these types of tasks soon!

Thank you very much for your reply! I am desperately looking forward to the emergence of related tasks! ! ! That would be so useful to me! !

Zelex commented 3 months ago

I am having this same issue. Was there ever a resolution?

Zelex commented 3 months ago

No matter what XML tags I wrap the file data with, it still screws up the response

WSC741606 commented 3 months ago

@Zelex I tried some methods but to no avail. In the end, I responded to this problem by generating multiple responses and filtering out the responses I thought were appropriate. I now guess it may be the effect of the system field in the web version.