Skip to content

Commit

Permalink
update to 0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnefedov committed Jul 26, 2023
1 parent 9dd7548 commit e0925e9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 72 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/release_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ jobs:

- name: Build artifact
run: mvn clean package -DskipTests

- name: Create Release
uses: ncipollo/[email protected]
with:
allowUpdates: true
artifacts: ${{ github.workspace }}/target/*.jar
token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to the Maven Central Repository
run: mvn --no-transfer-progress deploy
Expand Down
145 changes: 80 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,38 @@

### Integration

#### Maven:

```xml

<dependency>
<groupId>io.github.artemnefedov</groupId>
<artifactId>javaai</artifactId>
<version>0.3.4</version>
</dependency>
```

#### Gradle:

```groovy
implementation group: 'io.github.artemnefedov', name: 'javaai', version: '0.3.4'
```
>#### _Maven_
>
>```xml
><dependency>
> <groupId>io.github.artemnefedov</groupId>
> <artifactId>javaai</artifactId>
> <version>0.3.5</version>
></dependency>
>```
> ___
>#### _Gradle_
>
>```groovy
>implementation 'io.github.artemnefedov:javaai:0.3.5'
>```
### Initialize JavaAI
```java
JavaAI javaAI = javaAiBuilder("YOUR_API-KEY");
```
> You can pass your API-Key in java code
>```java
>JavaAI javaAI = javaAiBuilder("YOUR_API-KEY");
>```
> ___
>
> Or paste it into the api-key field in the _**javaai.yaml**_, everyone loves yaml
>```yaml
>openai:
> api-key: "YOUR_API-KEY"
>```
>```java
>JavaAI javaAI = javaAiBuilder();
>```
## Java AI example
Expand All @@ -45,51 +55,64 @@ JavaAI javaAI = javaAiBuilder("YOUR_API-KEY");
You can make a first request using List<ChatMessage> to set the context and get a response, and after that use a string.
<br>Both options retain the message history.
<br>The "**assistant**" role is used by default for answers, be careful.
```java
var messages=List.of(
new ChatMessage("user","Hello!"),
new ChatMessage("assistant","Hello! How can I assist you today?"));

String chatResponse = javaAI.chat(messages);
```
#### _OR_
```java
javaAI.chat("What's 2 2?"); // answer: 2 + 2 equals 4.
javaAI.chat("What did I ask in the last question?"); //answer: In your last question, you asked "What's 2 2?"
```

### Completions
```java
//Text generation, the model will return the response as a String
String response = javaAI.generateText("Say this is a test");
```

>```java
>var messages = List.of(
> new ChatMessage("user","Hello!"),
> new ChatMessage("assistant","Hello! How can I assist you today?"));
>
>String chatResponse = javaAI.chat(messages);
>```
>#### _OR_
>```java
>javaAI.chat("What's 2 2?");
>javaAI.chat("What did I ask in the last question?");
>```
> > **user:** What's 2 2?<br>
> > **assistant:** 2 + 2 equals 4<br>
> > **user**: What did I ask in the last question?<br>
> > **assistant**: In your last question, you asked "What's 2 2?"<br>
---
### DALL·E 2
```java
//Image generation, the model will return a URL/ to the result, as a List of String
String imgUrl=javaAI.generateImage("A cute baby sea otter");
```

>Image generation, the model will return a URL to the result, as a List of String
>```java
>String imgUrl = javaAI.generateImage("cat sitting next to a cup of coffee");
>```
> ![cat_image](https://github.com/artemnefedov/JavaAI/blob/resource/img/cat_%20of_coffee.png?raw=true)
---
### Completions
>Text generation, the model will return the response as a String
>```java
>String response = javaAI.generateText("Say this is a test");
>```
---

**Notice:**
> You can always set your parameters for the models
Example for Chat:

```java
javaAI.setChat(
Chat.builder()
.messages(new ArrayList<>())
.model("gpt-3.5-turbo")
.maxTokens(2000)
.n(1)
.build()
);
```

> _In java code_
>```java
>javaAI.setChat(
> Chat.builder()
> .messages(new ArrayList<>())
> .model("gpt-3.5-turbo")
> .maxTokens(2000)
> .n(1)
> .build()
> );
>```
> _or in **javaai.yaml**_
> ```yaml
> chat:
> model: gpt-3.5-turbo
> temperature: 0.9
> top_p: 1
> n: 1
> stream: false
> stop: \n
> max_tokens: 2000
> user:
> ```
---
## Models that JavaAI works with:
Expand All @@ -99,14 +122,6 @@ javaAI.setChat(
3. [x] [Create image](https://platform.openai.com/docs/api-reference/images/create)
---

## Outside Dependencies.

* [Gson](https://github.com/google/gson)
* [lombok](https://github.com/projectlombok/lombok)
* [junit](https://github.com/junit-team/junit5)
* [logback-classic](https://mvnrepository.com/artifact/ch.qos.logback/logback-classic)

## License
#### Distributed under the [MIT License](./LICENSE)

0 comments on commit e0925e9

Please sign in to comment.