Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Cannot access OpenRouter models #506

Open
stevevestal opened this issue May 20, 2024 · 1 comment
Open

Cannot access OpenRouter models #506

stevevestal opened this issue May 20, 2024 · 1 comment

Comments

@stevevestal
Copy link

stevevestal commented May 20, 2024

Another member of our team is able to access an OpenRouter model using his Python client. Here are the parameters (in Java-speak).

String userKey = "<user key for openrouter>";
String model = "mistralai/mistral-7b-instruct:free";
String baseURL ="https://openrouter.ai/api/v1/";

Below are two variations of code I have used. With the above parameters, I get an HTTP 404 when the final line in each variant is executed. If I use the parameters

      String userKey = "<user key for openai>";
      String baseURL = "https://api.openai.com/"; 
      String model = "babbage-002"; 

then both of the following at least get to the point of demanding more money.

This one uses #454

        OkHttpClient okHttpClient = OpenAiService.defaultClient(userKey, Duration.ofSeconds(10));
        Retrofit retrofitX = OpenAiService.defaultRetrofit(okHttpClient, OpenAiService.defaultObjectMapper()).newBuilder()
                .baseUrl(baseURL)
                .build();
        OpenAiApi openAiApi = retrofitX.create(OpenAiApi.class);
        OpenAiService service = new OpenAiService(openAiApi, okHttpClient.dispatcher().executorService());       
        System.out.println("\nCreating completion...");
        CompletionRequest completionRequest = CompletionRequest.builder()
                .model(model)
                .prompt("Somebody once told me the world is gonna roll me")
                .echo(true)
                .user("testing")
                .n(3)
                .build();
        System.out.println("\nCompletionRequest built");
        service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
        System.out.println("\nCompletion created");      

Here is another one I saw somewhere.

        ObjectMapper mapper = OpenAiService.defaultObjectMapper();
        OkHttpClient client = OpenAiService.defaultClient(userKey, Duration.ofSeconds(30))
                .newBuilder()
                .build();
        Retrofit retrofit = null;
		try {
			retrofit = OpenAiService.defaultRetrofit(client, mapper)
			        .newBuilder()
			        .baseUrl(new URL(baseURL))
			        .build();
		} catch (MalformedURLException e) {
			return;
		}
        OpenAiApi api = retrofit.create(OpenAiApi.class);
        OpenAiService service = new OpenAiService(api);      
        
        System.out.println("\nCreating completion...");
        CompletionRequest completionRequest = CompletionRequest.builder()
                .model(model)
                .prompt("Somebody once told me the world is gonna roll me")
                .echo(true)
                .user("testing")
                .n(3)
                .build();
        System.out.println("\nCompletionRequest built");
        service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
@vacuityv
Copy link
Contributor

@stevevestal since this repo had no merge for a long time. I think you can try my repo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants