Tuesday, April 2, 2024

DeepSeek 6.7B Prompts in the Same Context

 In the previous post, code was generated in two different ways within the Continue plugin, inline and maintaining context. This time I'm going to focus on maintaining context and try to generate code with different prompts to see how easily code can be modified. All of these examples are done in Continue using the DeepSeek 6.7b model and would need to be copied into an actual file. All the files are available on github.

pom.xml

prompt: create a pom file for spring boot

     ⋮
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
     ⋮
  <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <!-- Add your other dependencies here -->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        <    class Solution {
    public boolean isAnagram(String s, String t) {
     ⋮
 
Some of it is close. Some does not apply at all. One of the problems with Generative AI seems to be you never really know what you are going to get. Full file
 
 
prompt: change spring boot to a parent
 
Not the best prompt. I was trying to remove the unneeded dependency on spring-boot-starter. This version did remove the non-XML at the bottom of the file though. This is one of the interesting parts of Generative AI. Each prompt generates something new. Full file
 
 
prompt: Use spring boot version 3.2.3
 
I'll come back to the dependency later. Trying to update the versions first. Full file
 
   
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
 
 
prompt: Use java 21
 
 
    <properties>
        <java.version>21</java.version> <!-- Use Java 21 -->
    </properties>
 
 
prompt: Add dependencies for spring boot jdbc and web 
 
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

 
 
 
prompt: Remove spring-boot-starter dependency
 
  <dependencies>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <!-- Add your other dependencies here -->
    </dependencies>

 
 
This turned out OK, but I think it was mostly luck. Things do not go quite as well in the next part with docker compose. Full file
 

docker-compose.yml

 prompt: create a docker-compose file to start postgres
 
 version: '3'
services:
  db:
    image: postgres:latest
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "mysecretpassword"
    volumes:
      - ./data:/var/lib/postgresql/data
    ports:
      - 5432:5432



prompt: Change password to postgres
 
version: '3'
services:
  db:
    image: postgres:latest
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
    volumes:
        - .:/var/lib/postgresql/data
    ports:
        - 5432:5432


Changes the password but loses the volume.


prompt: Add restart unless-stopped
 
version: '3'
services:
  db:
    image: postgres:latest
    environment:
      POSTGRES_USER: "postgres"
      POSTGERS_PASSWORD: "postgres"
    volumes:
      - .:/var/lib/postgresql/data
    ports:
      - 5432:5432
    restart: unless-stopped


I was hoping it would self repair but it did not. Also changed POSTGRES_PASSWORD.
 
 
I tried again with with prompts trying to prevent a change.


prompt: create a docker-compose file to start postgres
 
version: '3'
services:
  db:
    image: postgres:latest
    restart: always
    environment:
      POSTGRES_USER: exampleuser
      POSTGRES_PASSWORD: examplepassword
      POSTGRES_DB: exampledb
    volumes:
      - ./data:/var/lib/postgresql/data
    ports:
      - 5432:5432


Added a POSTGRES_DB this time.


prompt: Change user and password to postgres. Do not change anything else.
 
version: '3'
services:
  db:
    image: postgres:latest
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: exampledb
    volumes:
       - .:/var/lib/postgresql/data
    ports:
       - 5432:5432

 
Still changed the volume.
 

prompt: Add restart unless-stopped. Do not change anything else.
 
version: '3'
services:
  db:
    image: postgres:latest
    restart: unless-stopped
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: exampledb
    volumes:
        - .: /var/lib/postgresql/data
    ports:
        - 5432:5432


At least it did not misspell POSTGRES this time.

application.properties

prompt: create application.properties with no banner
 
# Banner Disabling
spring.main.banner-mode=off


Worked.


prompt: turn on virtual threads in application.properties
 
Couldn't do this,  because the model is too old. It thinks it is a preview feature.

SQL

prompt: create a postgresql fruit table and fill it with fruit
 
CREATE TABLE fruit(
    id SERIAL PRIMARY KEY,
    name VARCHAR(100),
    color VARCHAR(100)
);

INSERT INTO fruit (name, color) VALUES ('Apple', 'Red');
INSERT INTO fruit (name, color) VALUES ('Banana', 'Yellow');
INSERT INTO fruit (name, color) VALUES ('Cherry', 'Red');
INSERT INTO fruit (name, color) VALUES ('Date', 'Yellowish Brown');


Fun that it can create this.

Conclusion

While Generative AI can be used to generate some code quickly, the output is inconsistent. Each prompt, even with context, can change the result. It is therefore important for the code to be thoroughly reviewed.